NightDev Community Forums

Cannot use $(count) within $(eval)


#1

This one has been driving me insane for a while now.

I want to use $(eval) to create commands that change their output when certain arguments are added. I’ve done this in the past, so I don’t have a problem with this (store $(query) in a string, .trim() it, then split it with .split() and check the correct array index for certain values). However, tonight I was trying to adapt a known working command to also store $(count) and perform some math on it based on what argument is passed. Here’s the command as written:

!editcom big $(eval let q = “$(query)”.trim(); let c=$(count); if (q.split(“ “)[0] === “count”) {`The “big” counter has rolled over ${Math.floor(c/397)} times.`} else {“b”+”i”.repeat(c%397+1)+”g”})

This should work, and if I change $(query) and $(count) to static numbers and run it in my browser console it works perfectly, but with Nightbot I get “Right-hand side of ‘instanceof’ is not an object.” It’s worth noting that the biggest change to the known working command is the addition of let c=$(count);, and by omitting that and the references to the count I don’t have any issues with the command.

I also tried the following commands:

!addcom !test $(eval let c=$(count); c)
!editcom !test $(eval let c=“$(count)”; c)
!editcom !test $(eval let c=Number(“$(count)”); c)

In previous versions of Nightbot, these would output the value of c, as you would expect it to. I have commands saved from months ago that used this exact type of syntax that worked without issue. Right now, you get “Right-hand side of ‘instanceof’ is not an object.”

I don’t know what it is about Nightbot’s $(eval) that hates $(count) so much, but something is wrong that is actively preventing me from being able to use this otherwise powerful platform.

EDIT: I swear that the short commands weren’t working before, but now they work just fine.


#2

@TheAppleFreak

Use straight quotes instead of curly ones. Or use backticks:

!editcom big $(eval let q=`$(query)`.trim();let c=$(count);if(q.split(` `)[0]===`count`){`The "big" counter has rolled over ${Math.floor(c/397)} times.`;}else{`b`+`i`.repeat(c%397+1)+`g`;})

#3

Some days I don’t understand Nightbot.

Thank you, though! That works just fine.