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");
}
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?
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.
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.
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.
Thanks. I may try that.
Use some log(LOG_DEBUG,...) before that call and see if it makes a difference.
I've had some quirks with synchronet JS where functions/js routines dont work, and implementing log(LOG_DEBUG,...) before it (to figure out why stuff wasnt working), made it work for some strange reason. (And then removing the log(), it reverted back to not working - so somehow it helped...)
If it fixes your situation, then hopefully helps get to the bottom of this...
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.
Thanks. I may try that.
Use some log(LOG_DEBUG,...) before that call and see if it makes a difference.
Re: directory() results affected by console.yesno()..?
By: deon to Nightfox on Fri Mar 29 2024 09:40 pm
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.
Thanks. I may try that.
Use some log(LOG_DEBUG,...) before that call and see if it makes a difference.
I found out what the problem was. I was using js.exec_dir in my call to directory(), and it looks like js.exec_dir can be indirectly changed (such as by console.yesno() running yesnobar.js from sbbs/exec). js.exec_dir has the directory of the currently running script (and I thought it would be the same throughout the same script, but it seems that's not the case).
Sysop: | Gary Ailes |
---|---|
Location: | Pittsburgh, PA |
Users: | 132 |
Nodes: | 5 (0 / 5) |
Uptime: | 109:06:44 |
Calls: | 733 |
Files: | 2,171 |
Messages: | 81,483 |