Grab game: calling multiple api?

Asked Nov 10, 2020·5 replies·Last activity 5 years ago·Open in Discord ↗
Archived from the original community forum
Things may have changed since it was written. Still stuck? Ask the community on Discord.

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!';})

5 replies

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 /t/customapi-blackjack-command/1534589348744269994 (I suggest passing the token too so someone can’t just call the second command and put whatever they want in the qoute list.)

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.

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.

Didn't find your answer? The community is on Discord.

Ask on Discord