node.js - NodeJS Logic Error? Program Stops as Soon as part of it is Executed? -
i pretty new nodejs , sorry :( gotta start somewhere. anyway, editing code trying finish, , came across challenge when trying make have 1 of commands (this bot) work. here's bit of code isn't working :/
steamfriends.on('friendmsg', (id, msg) => { if (msg == '') {} else { log(id + ' sent me ' + '"' + msg + '"') } if (config.get('admins').indexof(id) == -1) return; if (msg.indexof('!price') == 0) { var match = msg.match(/!price (director|audition) ([\.0-9]+)/); if (!match) steamfriends.sendmessage(id, 'usage: !price <director or audtion> <price> (e.g. !price director 3.77)'); else { steamfriends.sendmessage(id, 'successfully set price of '+match[1] + ' reels '+match[2] + '!'); prices[match[1] == 'audition' ? 0 : 1] = parsefloat(match[2]); changeprices(); } } else if(msg.indexof('!changestate') == 0) { var match = msg.match(/!changestate (online|offline|away|busy|lookingtotrade|lookingtoplay|snooze)/); log(match); log(match[1]); if (!match) steamfriends.sendmessage(id, '!changestate <state> (online, offline, away, lookingtotrade, busy, lookingtoplay, snooze)'); var state = match[1] if (match) steamfriends.setpersonastate(steam.epersonastate.state) } });
so top part works, bottom part not. bottom part else if statement should triggered keyword !changestate top part (the part works) part triggered !price.
example: when try !changestate away, should executed steamfriends.setpersonastate(steam.epersonastate.away) code not return error, logs "!changestate away, away" , on next line, "away". i'm not sure if logic error or else in code going wrong :/
i've had log match , match[1] debugging, nothing seems help.
thanks guys, appreciate it.
at end of code have
steamfriends.setpersonastate(steam.epersonastate.state)
your 'state' variable isn't being used here. suspect have more luck like
switch(state.tolowercase()) { case 'away': steamfriends.setpersonastate(steam.epersonastate.away); break; case 'online': steamfriends.setpersonastate(steam.epersonastate.online); break; // etc... }
Comments
Post a Comment