How do i put a javascript variable in $(urlfetch) url

I currently have this command:
if(1==1){var code = “code1”;}else{var code = “code2”;}
var json = $(urlfetch json code variable here ?top=1&embed=players))
To get the current world record from a game.
Is it possible to put the “code” variable in the json url, if so how?

Thanks in advance!

You have to nest the eval that calculates the URL part inside the urlfetch.

Know that if you need to use some other Nightbot variable inside the eval that calculates the URL part, you will have to use two commands (one an alias of the other) in order to circumvent the variable nesting limit.

$(eval var json = $(urlfetch json$(eval if(1==1){"code1"}else{"code2"})?top=1&embed=players))

That makes a lot of sense.
Thanks a lot!

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