• directory() results affected by console.yesno()..?

    From Nightfox@VERT/DIGDIST to Digital Man on Wednesday, March 27, 2024 20:31:05
    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?

    Nightfox

    ---
    ■ Synchronet ■ Digital Distortion: digitaldistortionbbs.com
  • From Digital Man@VERT to Nightfox on Thursday, March 28, 2024 14:27:40
    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
    ---
    ■ Synchronet ■ Vertrauen ■ Home of Synchronet ■ [vert/cvs/bbs].synchro.net
  • From Nightfox@VERT/DIGDIST to Digital Man on Thursday, March 28, 2024 15:25:08
    Re: directory() results affected by console.yesno()..?
    By: Digital Man to Nightfox on Thu Mar 28 2024 02:27 pm

    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.

    gah.. I've done that before. Just wasn't paying attention to my loop variable names.

    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.

    Nightfox

    ---
    ■ Synchronet ■ Digital Distortion: digitaldistortionbbs.com
  • From deon@VERT/ALTERANT to Nightfox on Friday, March 29, 2024 21:40:28
    Re: directory() results affected by console.yesno()..?
    By: Nightfox to Digital Man on Thu Mar 28 2024 03:25 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'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...


    ...δεσ∩

    ---
    ■ Synchronet ■ AnsiTEX bringing back videotex but with ANSI
  • From Nightfox@VERT/DIGDIST to deon on Friday, March 29, 2024 09:56:02
    Re: directory() results affected by console.yesno()..?
    By: deon to Nightfox on Fri Mar 29 2024 09:40 pm

    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...

    Thanks for the suggestion.

    Nightfox

    ---
    ■ Synchronet ■ Digital Distortion: digitaldistortionbbs.com
  • From Nightfox@VERT/DIGDIST to deon on Friday, March 29, 2024 22:33:08
    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).

    Nightfox

    ---
    ■ Synchronet ■ Digital Distortion: digitaldistortionbbs.com
  • From Digital Man@VERT to Nightfox on Saturday, March 30, 2024 10:10:50
    Re: directory() results affected by console.yesno()..?
    By: Nightfox to deon on Fri Mar 29 2024 10:33 pm

    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).

    Yeah, it's a bug that I'll fix.
    --
    digital man (rob)

    This Is Spinal Tap quote #14:
    The Boston gig has been cancelled. [Don't] worry, it's not a big college town. Norco, CA WX: 47.4°F, 94.0% humidity, 2 mph WNW wind, 0.56 inches rain/24hrs ---
    ■ Synchronet ■ Vertrauen ■ Home of Synchronet ■ [vert/cvs/bbs].synchro.net