Grab game: calling multiple api?

So I’m trying to make a sort of chat game where users can grab other users with a percent chance to fail. i also want nightbot to record the successes and failures using the quote_system api so that i can bring up a score board later. However, when ever the !grab command runs it seems to be running the api in both branches and adding to both success and failure regardless of result. Is there a way to have it only run the api in one branch?

$(eval v=’$(user)’; u=$(query); t = [‘0’, ‘0’, ‘0’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’]; a=t[Math.floor(Math.random() * t.length)]; if(a==‘1’) {$(urlfetch https://twitch.center/customapi/addquote?token=mytoken&data=grabS); v+’ grabbed ‘+u+’ successfully!’;} else {$(urlfetch https://twitch.center/customapi/addquote?token=mytoken&data=grabF) ; u+’ resisted ‘+v+’‘s grab!’;})

The problem with you command is that the urlfetch are always called due the the way nightbot works.
I would suggest using the alias ability and passing information to a second command which then does the uslfetch. If you want an example of something similar you can look here [CustomAPI] BlackJack command (I suggest passing the token too so someone can’t just call the second command and put whatever they want in the qoute list.)

3 Likes

How would you call an alias here? i think i tried using something like if(a==1) -a=!win else -a=!lose but it didn’t work

Well basically what your gonna wanna do is have the first command decide the response and out put something like:

Private_Token&data=grabS Message you want it to say.

And then have the second command read it like this:

$(eval a=`$(urlfetch https://twitch.center/customapi/addquote?token=$(1))`;`$(query)`.slice(26))

So basically the first command won’t Have the urlfetch and just return the ending part of the grab addqoute command

If your still confused I can probably write out a command for you.

1 Like

I’ll fiddle around with it some.
Would it be possible to construct the url as a string and then pass it to urlfetch?
if (a==1) b=url+grabS; else b=url+grabF; c=$(urlfetch b)

No because of the way nightbot treat variables. Basically the ones on the inside are done first so the urlfetch will always be done before the eval even starts.

1 Like

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