• Add and object to an array

    From Mortifis@VERT/ALLEYCAT to All on Thu Jul 18 17:04:09 2019
    Trying to do a list type array that is a list of objects. ieãconst dup_user = {ã number: '',ã alias: '',ã num: '',ã email: '',ã dup_alias: '',ã dup_num: '',ã dup_email: '' ã}ããvar user_list = []; // ??ããI'd like to populate by running a nested loop that compares users names:ãlastuser=system.lastuser;ããfor(i=1; i<=lastuser; i++) // loop through users and grab the nameã{ã u = new User(i);ã ã if(u.settings&(USER_DELETED|USER_INACTIVE))ã continue;ãã // start new new loop and compare nameã for(n = i+1; n <= lastuser; n++)ã {ã d = new User(n)ã if(u.number == d.number) continue;ã if(d.settings&(USER_DELETED|USER_INACTIVE)) continue;ã ã if(u.name == d.name) ã {ã ... do some stuff and add the values to an arrayã that can be accessed by the index [x] later on ã is there a push.dup_user(user_list) type expression?ãã } ã}ããããMy teachers always said "You can't make a living looking out a window!", theyãwere wrong, I drive truck :-Pãã---ã þ Synchronet þ AlleyCat! BBS -
    http://alleycat.synchro.net:81ã
  • From echicken@VERT/ECBBS to Mortifis on Thu Jul 18 16:14:56 2019
    Re: Add and object to an arrayã By: Mortifis to All on Thu Jul 18 2019 17:04:09ãã Mo> var user_list = []; // ??ã Mo> d = new User(n)ã Mo> if(u.number == d.number) continue;ã Mo> if(d.settings&(USER_DELETED|USER_INACTIVE)) continue;ã Mo> if(u.name == d.name) ã Mo> {ã Mo> ... do some stuff and add the values to an arrayã Mo> that can be accessed by the index [x] later on ã Mo> is there a push.dup_user(user_list) type expression?ã Mo> } ããuser_list.push({ã number: d.number,ã alias: d.alias,ã ...ã});ãã---ãechickenãelectronic chicken bbs - bbs.electronicchicken.comã þ Synchronet þ electronic chicken bbs - bbs.electronicchicken.comã
  • From Mortifis@VERT/ALLEYCAT to echicken on Thu Jul 18 17:40:34 2019
    Re: Add and object to an arrayã > By: Mortifis to All on Thu Jul 18 2019 17:04:09ãã > Mo> var user_list = []; // ??ã > Mo> d = new User(n)ã > Mo> if(u.number == d.number) continue;ã > Mo> if(d.settings&(USER_DELETED|USER_INACTIVE)) continue;ã > Mo> if(u.name == d.name) ã > Mo> {ã > Mo> ... do some stuff and add the values to an arrayã > Mo> that can be accessed by the index [x] later on ã > Mo> is there a push.dup_user(user_list) type expression?ã > Mo> } ãã > user_list.push({ã > number: d.number,ã > alias: d.alias,ã > ...ã > });ããThank you ... and to access it later:ããfor (var i = 0; i < user_list.length; i++) {ã print(user_list[i]+"\r\n");ã}ãã??ããããMy teachers always said "You can't make a living looking out a window!", theyãwere wrong, I drive truck :-Pãã---ã þ Synchronet þ AlleyCat! BBS - http://alleycat.synchro.net:81ã
  • From echicken@VERT/ECBBS to Mortifis on Thu Jul 18 17:21:11 2019
    Re: Re: Add and object to an arrayã By: Mortifis to echicken on Thu Jul 18 2019 17:40:34ãã Mo> for (var i = 0; i < user_list.length; i++) {ã Mo> print(user_list[i]+"\r\n");ã Mo> }ããThen you'd get a whole bunch of [object Object] output or something similar (you're tryingãto print each array element, as a string, but they're objects). Something like this:ãã print(user_list[i].alias + '\r\n');ããor this:ãã print(JSON.stringify(user_list[i]));ããor this, without the for loop:ãã print(JSON.stringify(user_list));ãã---ãechickenãelectronic chicken bbs - bbs.electronicchicken.comã þ Synchronet þ electronic chicken bbs - bbs.electronicchicken.comã
  • From Mortifis@VERT/ALLEYCAT to echicken on Thu Jul 18 18:30:52 2019
    Re: Re: Add and object to an arrayã > By: Mortifis to echicken on Thu Jul 18 2019 17:40:34ãã > Mo> for (var i = 0; i < user_list.length; i++) {ã > Mo> print(user_list[i]+"\r\n");ã > Mo> }ãã > Then you'd get a whole bunch of [object Object] output or something similarã > (you're tryingã > to print each array element, as a string, but they're objects). Somethingã > like this:ãã > print(user_list[i].alias + '\r\n');ãã > or this:ãã > print(JSON.stringify(user_list[i]));ãã > or this, without the for loop:ãã > print(JSON.stringify(user_list));ããexcellent, thank you. And, yes, that's what I was getting [object Object] Iãtried a bunch of methods I researched but none of them worked. still not sureãhow to get console.log() to work, says undefined.ãããããMy teachers always said "You can't make a living looking out a window!", theyãwere wrong, I drive truck :-Pãã---ã þ Synchronet þ AlleyCat! BBS - http://alleycat.synchro.net:81ã
  • From echicken@VERT/ECBBS to Mortifis on Thu Jul 18 17:53:01 2019
    Re: Re: Add and object to an arrayã By: Mortifis to echicken on Thu Jul 18 2019 18:30:52ãã Mo> I tried a bunch of methods I researched but none of them worked. still notã Mo> sure how to get console.log() to work, says undefined.ããconsole.log() is a thing in web browsers and in node.js, but not in Synchronet's JSãenvironment. Some JS examples you see on the web won't transfer perfectly into this space.ããWe do have the log(level, message) function here:ãã log(LOG_DEBUG, 'This is a debug message');ããor you can omit the loglevel parameter:ãã log('This is a message, probably at the INFO level (?)');ããThe LOG_* level variables are defined in sbbsdefs.js.ãã---ãechickenãelectronic chicken bbs - bbs.electronicchicken.comã þ Synchronet þ electronic chicken bbs - bbs.electronicchicken.comã
  • From Nightfox@VERT/DIGDIST to Mortifis on Thu Jul 18 15:01:19 2019
    Re: Add and object to an arrayã By: Mortifis to All on Thu Jul 18 2019 05:04 pmãã Mo> var user_list = []; // ??ãã Mo> ... do some stuff and add the values to an arrayã Mo> that can be accessed by the index [x] later on ã Mo> is there a push.dup_user(user_list) type expression?ããIf I understand you, do you want to add/append to the user_list array? Youãshould be able to do this:ããuser_list.push(dup_user);ããYou can also append literal objects:ããuser_list.push({ã number: '',ã alias: '',ã num: '',ã email: '',ã dup_alias: '',ã dup_num: '',ã dup_email: ''ã});ããNightfoxãã---ã þ Synchronet þ Digital Distortion: digitaldistortionbbs.comã
  • From Mortifis@VERT/ALLEYCAT to Nightfox on Thu Jul 18 20:14:00 2019
    Re: Add and object to an arrayã > By: Mortifis to All on Thu Jul 18 2019 05:04 pmãã > Mo> var user_list = []; // ??ãã > Mo> ... do some stuff and add the values to an arrayã > Mo> that can be accessed by the index [x] later on ã > Mo> is there a push.dup_user(user_list) type expression?ãã > If I understand you, do you want to add/append to the user_list array? Youã > should be able to do this:ãã > user_list.push(dup_user);ãã > You can also append literal objects:ãã > user_list.push({ã > number: '',ã > alias: '',ã > num: '',ã > email: '',ã > dup_alias: '',ã > dup_num: '',ã > dup_email: ''ã > });ãããThank you, I appreciate it. ããããMy teachers always said "You can't make a living looking out a window!", theyãwere wrong, I drive truck :-Pãã---ã þ Synchronet þ AlleyCat! BBS - http://alleycat.synchro.net:81ã
  • From Mortifis@VERT/ALLEYCAT to echicken on Thu Jul 18 20:16:09 2019
    Re: Re: Add and object to an arrayã > By: Mortifis to echicken on Thu Jul 18 2019 18:30:52ãã > Mo> I tried a bunch of methods I researched but none of them worked. stillã > Mo> not sure how to get console.log() to work, says undefined.ãã > console.log() is a thing in web browsers and in node.js, but not inã > Synchronet's JSã > environment. Some JS examples you see on the web won't transfer perfectlyã > into this space.ãã > We do have the log(level, message) function here:ãã > log(LOG_DEBUG, 'This is a debug message');ãã > or you can omit the loglevel parameter:ãã > log('This is a message, probably at the INFO level (?)');ããI saw that, I had thought that writes to a file in /sbbs/data/logs/ãããããMy teachers always said "You can't make a living looking out a window!", theyãwere wrong, I drive truck :-Pãã---ã þ Synchronet þ AlleyCat! BBS - http://alleycat.synchro.net:81ã
  • From Digital Man@VERT to Mortifis on Thu Jul 18 16:30:27 2019
    Re: Re: Add and object to an arrayã By: Mortifis to echicken on Thu Jul 18 2019 08:16 pmãã > > Re: Re: Add and object to an arrayã > > By: Mortifis to echicken on Thu Jul 18 2019 18:30:52ã >ã > > Mo> I tried a bunch of methods I researched but none of them worked.ã > > Mo> still not sure how to get console.log() to work, says undefined.ã >ã > > console.log() is a thing in web browsers and in node.js, but not inã > > Synchronet's JSã > > environment. Some JS examples you see on the web won't transferã > > perfectly into this space.ã >ã > > We do have the log(level, message) function here:ã >ã > > log(LOG_DEBUG, 'This is a debug message');ã >ã > > or you can omit the loglevel parameter:ã >ã > > log('This is a message, probably at the INFO level (?)');ã >ã > I saw that, I had thought that writes to a file in /sbbs/data/logs/ããThat depends. It goes where log output goes which may be to the BBS's local console, to windows in the Synchronet Control Panel, to files, to the Windows NT event viewer, to *nix syslog (and whatever it does with it) - so yeah, log() messages can go all kinds of places.ãã digital manããSynchronet/BBS Terminology Definition #42:ãISDN = Integrated Services Digital NetworkãNorco, CA WX: 83.5øF, 50.0% humidity, 14 mph E wind, 0.00 inches rain/24hrsã---ã þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.netã
  • From echicken@VERT/ECBBS to Mortifis on Thu Jul 18 19:50:51 2019
    Re: Re: Add and object to an arrayã By: Mortifis to echicken on Thu Jul 18 2019 20:16:09ãã Mo> I saw that, I had thought that writes to a file in /sbbs/data/logs/ããIt goes wherever your log output goes (which varies with how your BBS is set up).ããWhere are you hoping to see these messages appear?ãã---ãechickenãelectronic chicken bbs - bbs.electronicchicken.comã þ Synchronet þ electronic chicken bbs - bbs.electronicchicken.comã
  • From Mortifis@VERT/ALLEYCAT to echicken on Fri Jul 19 09:08:39 2019
    Re: Re: Add and object to an arrayã > By: Mortifis to echicken on Thu Jul 18 2019 20:16:09ãã > Mo> I saw that, I had thought that writes to a file in /sbbs/data/logs/ãã > It goes wherever your log output goes (which varies with how your BBS is setã > up).ãã > Where are you hoping to see these messages appear?ããjust standard stdout (the screen) to generate a menu.ããããMy teachers always said "You can't make a living looking out a window!", theyãwere wrong, I drive truck :-Pãã---ã þ Synchronet þ AlleyCat! BBS - http://alleycat.synchro.net:81ã
  • From Mortifis@VERT/ALLEYCAT to echicken on Fri Jul 19 09:47:27 2019
    Re: Re: Add and object to an arrayã > By: Mortifis to echicken on Thu Jul 18 2019 20:16:09ãã > Mo> I saw that, I had thought that writes to a file in /sbbs/data/logs/ãã > It goes wherever your log output goes (which varies with how your BBS is setã > up).ããBleh, ... backstory, I gotr hurt at work and am trying to learn new stuffies soãI chose JS ... I know how to do these things with php ... anyway, it seems theãJS examples and such are a little different in sbbs js (JavaScript-C 1.8.5)?ããSo, I used: dup_list.push({number: u.number, num: u.number, alias: u.alias,ãemail: u.netmail, d_num: d.number, d_alias: d.alias});ããand thought it could be accessed with a console promptããif(js.global.console)ã edit=console.getstr(70,K_LINE);ãelseã edit=readln();ã ãif(edit=="") {ã print("\r\n\r\nExiting ...\r\n\r\n");ã exit();ã}ããprintf("Loading Record " + edit);ããconst dupUser = dup_list.find(dup_list => dup_list.number === edit);ããbut I get a syntax error :-/ããNo wonder I keep going back to php lolãããMy teachers always said "You can't make a living looking out a window!", theyãwere wrong, I drive truck :-Pãã---ã þ Synchronet þ AlleyCat! BBS -
    http://alleycat.synchro.net:81ã
  • From echicken@VERT/ECBBS to Mortifis on Fri Jul 19 09:56:04 2019
    Re: Re: Add and object to an arrayã By: Mortifis to echicken on Fri Jul 19 2019 09:08:39ãã >> Where are you hoping to see these messages appear?ãã Mo> just standard stdout (the screen) to generate a menu.ããwrite() and writeln() should work anywhere IIRC. If you're running your script under jsexec these areãwhat you'll want (along with prompt, confirm, and deny).ããWe do have a 'console' object, which represents the remote terminal in a telnet/rlogin/ssh session, andãis not to be confused with the console object that exists in other JS environments (browser, node.js). ãThe console.putmsg() method is generally the best thing to use if you want to send a string to the remoteãterminal.ããAs always, see http://nix.synchro.net/jsobjs.html for details on what's available.ãã---ãechickenãelectronic chicken bbs - bbs.electronicchicken.comã þ Synchronet þ electronic chicken bbs - bbs.electronicchicken.comã
  • From echicken@VERT/ECBBS to Mortifis on Fri Jul 19 11:10:08 2019
    Re: Re: Add and object to an arrayã By: Mortifis to echicken on Fri Jul 19 2019 09:47:27ãã Mo> const dupUser = dup_list.find(dup_list => dup_list.number === edit);ããFat-arrow functions and implicit return are ES6 features, while we're still on 5.1 here. This means thatãyou have to spell out 'function () {}' in full, and you must explicitly return a value.ããThis won't work, but to illustrate the equivalent syntax:ãã const dupUser = dup_list.find(function (e) {ã return e.number === edit;ã });ããHowever our Array object does not have a 'find' method, which is also new, so that's a no-go.ããThere are other ways to achieve this:ãã var dupUser;ã for (var n = 0; n < dup_list.length; n++) {ã if (dup_list[n].number !== edit) continue;ã dupUser = dup_list[n];ã break;ã }ããOr:ãã var dupUser;ã dup_list.some(function (e) {ã if (e.number !== edit) return false;ã dupUser = e;ã return true;ã });ããOr you could put a polyfill at the top of your script:ãã Array.prototype.find = function (f) {ã var ret;ã var self = this;ã this.some(function (e, i) {ã if (!f(e)) return false;ã ret = self[i];ã return true;ã });ã return ret;ã }ããAnd then 'find' would be available on Array and my "this won't work" example above would actually work.ããIn any of the above cases, dupUser will either be the element from your dup_list array, or it will beãundefined.ãã---ãechickenãelectronic chicken bbs - bbs.electronicchicken.comã þ Synchronet þ electronic chicken bbs - bbs.electronicchicken.comã
  • From Mortifis@VERT/ALLEYCAT to echicken on Sat Jul 20 14:03:15 2019
    Re: Re: Add and object to an arrayã > By: Mortifis to echicken on Thu Jul 18 2019 20:16:09ãã > Mo> I saw that, I had thought that writes to a file in /sbbs/data/logs/ãã > It goes wherever your log output goes (which varies with how your BBS is setããHmmm ... I used log(LOG_INFO,"dup_user_check: (" + dateTime + ") " + msg);ãbut I do not see the entry in any /sbbs/data/logs/*.log file :/ããããMy teachers always said "You can't make a living looking out a window!", theyãwere wrong, I drive truck :-Pãã---ã þ Synchronet þ AlleyCat! BBS - http://alleycat.synchro.net:81ã
  • From echicken@VERT/ECBBS to Mortifis on Sat Jul 20 14:07:45 2019
    Re: Re: Add and object to an arrayã By: Mortifis to echicken on Sat Jul 20 2019 14:03:15ãã Mo> Hmmm ... I used log(LOG_INFO,"dup_user_check: (" + dateTime + ") " + msg);ã Mo> but I do not see the entry in any /sbbs/data/logs/*.log file :/ããI think in the case of something running under jsexec it'll just show up on stdout. Can't remember.ãã---ãechickenãelectronic chicken bbs - bbs.electronicchicken.comã þ Synchronet þ electronic chicken bbs - bbs.electronicchicken.comã
  • From Digital Man@VERT to Mortifis on Sat Jul 20 11:40:47 2019
    Re: Re: Add and object to an arrayã By: Mortifis to echicken on Sat Jul 20 2019 02:03 pmãã > > Re: Re: Add and object to an arrayã > > By: Mortifis to echicken on Thu Jul 18 2019 20:16:09ã >ã > > Mo> I saw that, I had thought that writes to a file in /sbbs/data/logs/ã >ã > > It goes wherever your log output goes (which varies with how your BBS isã > > setã >ã > Hmmm ... I used log(LOG_INFO,"dup_user_check: (" + dateTime + ") " + msg);ã > but I do not see the entry in any /sbbs/data/logs/*.log file :/ããlog() output from jsexec goes to stdout by default. But there are command-line options to control where the console output from jsexec goes.ããã digital manããThis Is Spinal Tap quote #18:ãSustain, listen to it. Don't hear anything. You would though were it playing.ãNorco, CA WX: 75.5øF, 60.0% humidity, 0 mph NW wind, 0.00 inches rain/24hrsã---ã þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.netã
  • From Mortifis@VERT/ALLEYCAT to Digital Man on Sat Jul 20 16:14:59 2019
    Re: Re: Add and object to an arrayã > By: Mortifis to echicken on Sat Jul 20 2019 02:03 pmãã > > > Re: Re: Add and object to an arrayã > > > By: Mortifis to echicken on Thu Jul 18 2019 20:16:09ãã > > > Mo> I saw that, I had thought that writes to a file inã > > > Mo> /sbbs/data/logs/ãã > > > It goes wherever your log output goes (which varies with how your BBSã > > > is setãã > > Hmmm ... I used log(LOG_INFO,"dup_user_check: (" + dateTime + ") " +ã > > msg); but I do not see the entry in any /sbbs/data/logs/*.log file :/ãã > log() output from jsexec goes to stdout by default. But there areã > command-line options to control where the console output from jsexec goes.ããOkay, thank you, I hacked a function mylog() { f = new File(logFile); ... }ãinto my script for now.ããããMy teachers always said "You can't make a living looking out a window!", theyãwere wrong, I drive truck :-Pãã---ã þ Synchronet þ AlleyCat! BBS - http://alleycat.synchro.net:81ã