Subj : directory() results affected by console.yesno()..? To : Nightfox From : Digital Man Date : Thu Mar 28 2024 02:27 pm Re: directory() results affected by console.yesno()..? By: Nightfox to Digital Man on Wed Mar 27 2024 08:31 pm > Hi DM, > > One of the mods/doors I've written which is in the Git repository is Good > Time Trivia (in xtrn/gttrivia). I just noticed an odd issue with it - It > seems the results of the directory() function are being affected by a > console.yesno() at a different point in the script. However, if I try to > reproduce it with a separate script using directory() and console.yesno(), I > can't reproduce it. > So I'm wondering if something else might be going on - though I don't know > what that might be at this point. > > Web link: > https://gitlab.synchro.net/main/sbbs/-/blob/master/xtrn/gttrivia/gttrivia.js > > In gttrivia.js, on line 763 (in the getQACategoriesAndFilenames() function), > it calls directory() to get a list of *.qa files (which are the category Q&A > files): > var QAFilenames = directory(js.exec_dir + "qa/*.qa"); > > > The game's main menu lets you view scores. On line 1420 (in the > showScores() function), it uses console.yesno() to prompt whether you want > to also view multi-BBS scores (in addition to local scores, which are shown > before that). > > What's happening is that after I view scores and that console.yesno() is > executed, directory() is returning an empty array, rather than returning an > array of the filenames. If I comment out that console.yesno() and just have > that variable set to true or false, directory() successfully returns an > array of the filenames each time. > > However, I tried reproducing the issue with this JS snippet, and was not > able to reproduce the issue: > > var showServerScoresConfirm = console.yesno(i + ": Show multi-BBS scores"); > var fileList = > directory("/home/erico/BBS/sbbs/xtrn/DigDist/gttrivia/qa/*.qa"); > console.print("# files: " + fileList.length + "\r\n"); > for (var i = 0; i < fileList.length; ++i) > console.print(fileList[i] + "\r\n"); > > > So, I can't think of a reason why this issue is happening in gttrivia.js.. > > I also tried putting my test block of code in a loop where it would run > twice, and I noticed that it only ran once: > for (var i = 0; i < 2; ++i) > { > var showServerScoresConfirm = console.yesno(i + ": Show multi-BBS > scores"); > var fileList = > directory("/home/erico/BBS/sbbs/xtrn/DigDist/gttrivia/qa/*.qa"); > console.print("# files: " + fileList.length + "\r\n"); > for (var i = 0; i < fileList.length; ++i) > console.print(fileList[i] + "\r\n"); > } You're using 'i' as the loop variable for both loops. That's not going to work (one of the problems with JS the 'var' keyword and rationale for the new 'let' keyword). Create/use a different variable name for the inner-loop. > I'm not sure if that odd behavior is related at all to the odd behavior with > directory() in gttrivia.js.. > > Also, without printing the filenames, the inner block runs twice, as > expected: for (var i = 0; i < 2; ++i) > { > var showServerScoresConfirm = console.yesno(i + ": Show multi-BBS > scores"); > var fileList = > directory("/home/erico/BBS/sbbs/xtrn/DigDist/gttrivia/qa/*.qa"); > console.print("# files: " + fileList.length + "\r\n"); > } > > > I'm at a bit of a loss as to these issues.. I'm curious if you might have > any ideas? Nothing obvious. If you do have a reduced test case that demonstrates the problem (without any other bugs), let me know. The directory() method is implemented as js_directory() in js_global.c, so if you wanted to make experimental changes (e.g. add debug output or whatever), that's where you'd do that. -- digital man (rob) Sling Blade quote #1: Karl: I've killed Doyle with a lawn mower blade. Yes, I'm right sure of it. Norco, CA WX: 67.0øF, 53.0% humidity, 9 mph W wind, 0.00 inches rain/24hrs .