Emily
June 15, 2022, 8:58am
2
Hey @uzumakininde !
I can’t read this code, this is asking too much efforts from me.
Thankfully you formatted it properly on the Discord, so I can tell you what the issue is: you went over the nesting limit, you need to rewrite your code so you don’t exceed two levels.
Here’s three topics that could help:
Hey @Fl_GUI !
It doesn’t work because you’re nesting too many $(eval), Nightbot has a limit of 2 levels regarding nesting, as said in the 2017 post you mentioned .
If you need more than two levels of nesting, you’ll have to make !test an alias to another command. !test can pass data to the alias, and the alias can access it with the query variable.
Also, I’m not sure I understand what you’re trying to do, so I can’t help. It’d be nice if we had more details, if you can’t include the links t…
Hey @jpegnight !
You identified the issue properly: you reached the nesting limit! Basically, you use way too many $(eval), you only need one.
Here’s how I’d write your code:
const idleResponses = `$(urlfetch json https://pastebin.com/raw/UmRNDXpa)`.split(`#`);
// $(urlfetch) isn't a native JS function, this is just for the example
const randomOutcome = Math.ceil(Math.random() * 10);
const goldAmount = Math.ceil(Math.random() * 100);
// the line above will generate a random number between 1 an…
I would do exactly as you did; nest an eval, which handles an if/else, inside other variables. You should also know that Nightbot allows up to 2 levels of variable nesting. Beyond that, variables don’t evaluate properly. If I wanted to write a command which involves logic that absolutely must go beyond 2 levels of nesting, I would use command aliases, which I think is what you must do if you still want to output different text based on the result of the if/else.
1 Like