Well, a switch()
is only useful when you have “a lot” of cases, when you have just two where one of them is a default I’d just use an if()/else
.
Also, I’d make u
and t
lowercase and use lowercase usernames in the tests, so you don’t have to care about casing in the switch()
, and in case it changes, just write it in lowercase everywhere.
$(eval u='$(user)'.toLowerCase(); t='$(touser)'.toLowerCase(); r='$(urlfetch json https://u.nu/AFdoF)'.split(';'); q=r[Math.floor(Math.random()*r.length)]; $(urlfetch json https://u.nu/VZFpR))
switch (u) {
case 'mellbell83':
switch (t) {
case 'hoodlumkira':
`${u} attempts to beat ${t} using their ${q} quirk, but ${t} used all for one to steal their quirk rendering them defenseless`;
break;
case 'saltibunni':
`${u} tries sneaking up on ${t} to use their ${q} quirk, but ${t} heard them and uses her blueflame quirk to trap ${u}`;
break;
case 'mellbell83':
`${u} tries to sneak up on ${t} to use their ${q} but, hoodlumkira interferes using all for one and steals ${u} quirk protecting ${t} and rendering ${u} helpless`;
break;
case 'shannonsully13':
`${u} tries to run up and use their ${q} to assasinate ${t} but, ${u} uses her erasure quirk to erase ${u}s quirk`;
break;
case 'nightbot':
`test ${q}`;
break;
default:
`${u} attempts to beat ${t} using their ${q} quirk, but ${t} used all for one to steal their quirk rendering them defenseless`;
}
break;
case 'hoodlumkira':
if (t === 'nightbot') {
`test ${q}`;
} else {
'Testing';
}
break;
default:
'No response yet';
}
Most of the time you can use single quotes '
, it’s only when you try to add variables to text without using +
that you need to use backticks `
, that’s called template literals, I explained that in the topic I linked when I first answered you.
Also it’s preferable to use spaces instead of tabs to help with readability.
Pay closer attention to the syntax of what you write, JavaScript is forgiving, but its syntax is still strict.
Finally, why this works:
r='$(urlfetch json https://u.nu/AFdoF)'.split(';'); q=r[Math.floor(Math.random()*r.length)];
but this doesn’t:
q='$(urlfetch json https://u.nu/AFdoF)'.split(';'); q[Math.floor(Math.random()*q.length)];
is just because you forget to store q[Math.floor(Math.random()*q.length)]
in a variable,
no need to introduce a new variable, although it’s preferable when working on proper code, but when it comes to Nightbot we’re trying to save space and variable names as much as possible, so this would work too:
q='$(urlfetch json https://u.nu/AFdoF)'.split(';'); q=q[Math.floor(Math.random()*q.length)];