Trying to trigger a D&D wild surge based on PasteBin Code

I’m a little experienced with code but this is stumping me.

So what I want to have happen is the user types in !wildsurge. Then a random thing based on the result of code located on PasteBin. Right now there’s only three things that can happen: roll 2 results, a message saying the user can see invisible things, and a modron with a random name appears. Ideally, I’ll be adding more possible results later. I also want to pull in three random users in chat for when results are supposed to affect others (ope, you’re caught in the fireball). Right now none of the results use the other three random users.

So right now my Nightbot message looks like this:

$(eval u=`$(user)`; r=`$(urlfetch https://decapi.me/twitch/random_user/timbluemage)`; s=`$(urlfetch https://decapi.me/twitch/random_user/timbluemage)`; t=`$(urlfetch https://decapi.me/twitch/random_user/timbluemage)`; $(urlfetch https://pastebin.com/raw/8c55vMK5))

And my pastebin code looks like this:

let caster = u;

let target1 = r;
let target2 = s;
let target3 = t;

const modronFirstNames = ['Alpha-', 'Beta-', 'Gamma-', 'Delta-', 'Epislon-', 'Zeta-', 'Eta-', 'Theta-', 'Iota-', 'Kappa-', 'Ia-', 'Mu-', 'Nu-', 'Xi-', 'Omicron-', 'Pi-', 'Rho-', 'Sigma-', 'Tau-', 'Upsilon-', 'Phi-', 'Chi-', 'Psi-', 'Omega-'];

let modronName = modronFirstNames[Math.floor(Math.random() * responses.length)] + Math.floor((Math.random() * 100) + 1));

const wildSurges = ['Double trouble!', 'For the next minute ' + caster + ' can see invisible things!', 'A modron has been summoned for 1 minute! Their name is ' + modronName];

let wildSurgeRolled = Math.floor(Math.random() * wildSurges.length);

let surgeResult;

if(wildSurgeRolled == 0)
{
    let doubleTrouble1 = 0;
    let doubleTrouble2 = 0;

    while((doubleTrouble1 == doubleTrouble2)||(doubleTrouble1==0)||(doubleTrouble2==0)
    {
        doubleTrouble1 = Math.floor(Math.random() * wildSurges.length)
        doubleTrouble2 = Math.floor(Math.random() * wildSurges.length)
    }
    
    surgeResult = caster + " unleashed a wild surge! Double trouble!" + wildSurges[doubleTrouble1] + ' ' + wildSurges[doubleTrouble2];
}
else
{
    surgeResult = caster + " unleashed a wild surge!" + wildSurges[wildSurgeRolled];
}

surgeResult;

I appreciate any help that is given.

1 Like

What exactly do you need help with it’s not exactly clear. Is there an error message when you use the command?

1 Like

‘Unexpected Identifier’ is the error message I’m getting. I get that response in my Twitch chat when I use the command.

The only error I noticed giving it a quick skim through was responses.length in this line as responses doesn’t exist.

I’ve fixed the error you mentioned (and some other syntax errors). It currently looks like this in Nightbot:

$(eval u=`$(user)`; r=`$(urlfetch https://decapi.me/twitch/random_user/timbluemage)`; s=`$(urlfetch https://decapi.me/twitch/random_user/timbluemage)`; t=`$(urlfetch https://decapi.me/twitch/random_user/timbluemage)`; $(urlfetch https://pastebin.com/raw/8c55vMK5))

Pastebin code looks like this:

code = { 
let caster = $(u);

let target1 = ${r};
let target2 = ${s};
let target3 = ${t};

const modronFirstNames = ["Alpha-", "Beta-", "Gamma-", "Delta-", "Epislon-", "Zeta-", "Eta-", "Theta-", "Iota-", "Kappa-", "Ia-", "Mu-", "Nu-", "Xi-", "Omicron-", "Pi-", "Rho-", "Sigma-", "Tau-", "Upsilon-", "Phi-", "Chi-", "Psi-", "Omega-"];

let modronName = modronFirstNames[Math.floor(Math.random() * modronFirstNames.length)] + Math.floor((Math.random() * 100) + 1);

const wildSurges = ["Double trouble!", "For the next minute " + caster + " can see invisible things!", "A modron has been summoned for 1 minute! Their name is " + modronName];

let wildSurgeRolled = Math.floor(Math.random() * wildSurges.length);

let surgeResult;

if(wildSurgeRolled == 0)
{
    let doubleTrouble1 = 0;
    let doubleTrouble2 = 0;

    while((doubleTrouble1 == doubleTrouble2)||(doubleTrouble1==0)||(doubleTrouble2==0))
    {
        doubleTrouble1 = Math.floor(Math.random() * wildSurges.length)
        doubleTrouble2 = Math.floor(Math.random() * wildSurges.length)
    }
    
    surgeResult = caster + " unleashed a wild surge! Double trouble!" + wildSurges[doubleTrouble1] + " " + wildSurges[doubleTrouble2];
}
else
{
    surgeResult = caster + " unleashed a wild surge!" + wildSurges[wildSurgeRolled];
}

return surgeResult;
}```

Usually the 'Unexpected Identifier' error comes up. If I remove Nightbot trying to get the other three users (r, s, and t) then my error becomes about a 400 character limit. I think I have more than one error going on here.

The 400 characters is because the last urlfetch should be $(urlfetch json link)
Also you don’t need the ${} and $() in the pastebin code for the variables

I’ve simplified the code a bunch just to get something working. Right now it’s just posting the code into Twitch chat instead of running it.
Here’s the Nightbot side of things.

$(eval r = "$(urlfetch https://decapi.me/twitch/random_user/timbluemage)"; code = "$(urlfetch json https://pastebin.com/raw/8c55vMK5)")

Here’s the Pastebin side of things.

code ={

let theUser = r;

const theMessage = theUser + ' has triggered the wild surge!';

return theMessage;
}

You don’t need qoutes in the urlfetch for the paste bin also you shouldn’t have code=.

I got it working! I’ll be adding more wild surge possibilities later but here’s the current working version if anyone wants to use it and add their own thing to it.

Nightbot

$(eval u="$(user)"; r="$(urlfetch  https://decapi.me/twitch/random_user/timbluemage)"; s="$(urlfetch  https://decapi.me/twitch/random_user/timbluemage)"; t="$(urlfetch  https://decapi.me/twitch/random_user/timbluemage)";$(urlfetch json https://pastebin.com/raw/XXXXXX))

Pastebin

let caster = u;
 
let target1 = r;
let target2 = s;
let target3 = t;

let modronNamePart1 = ['Alpha','Beta','Omega','Gamma','Epsilon'];

let modronNamePart2 = Math.floor(Math.random() * 100);

let modronName = modronNamePart1[Math.floor(Math.random() * modronNamePart1.length)] + '-' + modronNamePart2;

let wildSurges = ['Double trouble!', 'For the next minute ' + caster + ' can see invisible things!', 'A modron has been summoned for 1 minute! Their name is ' + modronName];
 
let wildSurgeRolled = Math.floor(Math.random() * wildSurges.length);
  
let surgeResult;

if(wildSurgeRolled == 0)
{
    let doubleSurge1 = Math.floor(Math.random() * wildSurges.length);
    
    let doubleSurge2 = Math.floor(Math.random() * wildSurges.length);
    
    while(doubleSurge1 == doubleSurge2 || doubleSurge1 == 0 || doubleSurge2 == 0)
    {
        doubleSurge1 = Math.floor(Math.random() * wildSurges.length);
    
        doubleSurge2 = Math.floor(Math.random() * wildSurges.length);
    }
    
    surgeResult = caster + ' unleashed a double wild surge! ' + wildSurges[doubleSurge1] + ' ' + wildSurges[doubleSurge2];
}
else
{
    surgeResult = caster + ' unleashed a wild surge! ' + wildSurges[wildSurgeRolled];
}

surgeResult;

Thanks potatoeaterlove for the help!

One more note and this thread should probably be closed: this is not optimized. Like, I added a fireball thing and it increased how long it takes to process dramatically. Sometimes it times out if a double trouble gets rolled, which may mean it needs to get eliminated all together. So if you decide to repurpose this code for your own channel keep that in mind.

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