If [condition] then [output] else [output]

2022 visit: it’s fun seeing where I started, now JavaScript is my best friend.

Hey there!

I’m trying to build a command with Nightbot which gives a different output depending of the input…
The command should display the server on which the streamer is playing depending of the game played.
I tried some things but I keep getting an error in return: "Right-hand side of 'instanceof' is not an object"

Disclaimer: I don’t know anything about javascript, but I try by using examples I find on the forum, haha!

So, here’s what I tried so far, they are pretty much all the same, I just tried different way to type it:

!addcom !server $(eval responses = {if($(twitch username “{{game}}”) = “game1”){response = “user is currently playing on server1.”}};{if($(twitch username “{{game}}”) = “game2”){response = “user is currently playing on server2.”}};{“user isn’t currently playing on a server.”})

!addcom !server $(eval responses = {if($(twitch username “{{game}}”) = “game1”){“user is currently playing on server1.”}};{if($(twitch username “{{game}}”) = “game2”){“user is currently playing on server2.”}};{“user isn’t currently playing on a server.”})

!addcom !server $(eval {if($(twitch username “{{game}}”) = “game1”){response = “user is currently playing on server1.”}};{if($(twitch username “{{game}}”) = “game2”){response = “user is currently playing on server2.”}};{response = “user isn’t currently playing on a server.”})

Any help is highly appreciated!
Thanks in advance!

Edit: I don’t have access to the control panel, I can only add commands via the Twitch chat…

Heya, try out something like this, the $(twitch) game variables are compared like strings so make sure you have quotes around them:

$(eval
    var r = false;
    if('$(twitch username "{{game}}")' == 'game1')
        r = 'server1';
    else if('$(twitch username "{{game}}")' == 'game2')
        r = 'game2';

    if(r)
        'User is currenty playing on: ' + r + '.';
    else
        'User isn\'t currently playing on a server.';
)

Thanks for the fast answer!
Unfortunately it doesn’t work, I get what you tried to make me do, and I feel like it should work, but it doesn’t…

I should have said that I don’t have access to the control panel, I can only add commands via the Twitch chat…

Anyway I tried copy/pasting it raw, and by tweaking it to try to make it fit the chat phrasing to add commands, it didn’t work. I must have been doing something wrong in my attempts to rephrase it.
Here’s my attempt that I feel was the closest to succeed:

!addcom !server $(eval var s = false; if{(‘$(twitch username “{{game}}”)’ == ‘game1’) s = ‘server1’}; else if{(‘$(twitch username “{{game}}”)’ == ‘game2’) s = ‘server2’}; if(s) {'User is currenty playing on: ’ + s + ‘.’} else {‘User isn’t currently playing on a server.’})

Fixed the code above, missed a ; Through chat is not a problem, just add !commands edit !server in front of it.

Thank you so much! It works perfectly!!! You’re the best! :heart:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.