Multiple responses from one command?

I’m trying to make a custom CAH game for my stream, where a user can use two seperate commands for questions or answers. How can I set the answer command to fetch ‘X’ answers if I add an integer after the command?

I have an additional command that has the same dependency on this which I want to roll a random number from 0-X digits, the command being !roll X. My current script is:

!roll 10
$(eval Math.floor((Math.random() * 10) + 1))

Update: using query, I’ve gotten my !roll command to work fine. Now, the issue is that I get “undefined” for rolling more than one CAH answer! Grr

Can you explain how answers are generated/fetched?

$(eval responses = $(urlfetch json 0"="); responses[Math.floor(Math.random() * responses.length)])

I have the responses formatted per line to be retrieved, as well as the answers. Currently looking into the repeat function, but didn’t originally think that I could use these more in-depth commands within such a basic medium. I am repeatedly getting this error: “Right-hand side of ‘instanceof’ is not an object.”

This is the current command I’m testing:
$(eval responses = $(urlfetch json 0"="); responses[Math.floor(Math.random() * responses.length)]).repeat($(query))

And its error: “Right-hand side of ‘instanceof’ is not an object.repeat(2)”

2 was the parameter I added in the chat command (!cahbtest 2)

Yeah I’m a bit of an idiot. I see there was a typo in the script, so I’m actually NOT getting an error when I try to repeat it, nightbot just adds .repeat(x) to the command’s response.

This command gets X answers by shuffling the array of answers, slicing it to be of length X, and joining the resulting array by spaces.

$(eval n=parseInt(decodeURIComponent("$(querystring)")||"1");if(isNaN(n)||n<=0||n>3){"Enter a positive integer less than 4"}else{rS=decodeURIComponent("$(querystring $(urlfetch json");try{r=JSON.parse(rS).split("=");for(i=r.length-1;i>0;i--){j=Math.floor(Math.random()*(i+1));[r[i],r[j]]=[r[j],r[i]]}r.slice(0,n).join(" ")}catch(e){`Failed to parse responses: ${e.message}: ${rS}`.substr(0,400)}})

You are amazing, thank you so much.

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