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:
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 0https://pastebin.com/raw/fvs7pJBN).split("="); 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 https://pastebin.com/raw/fvs7pJBN))");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)}})