I have Javascript code that has to do something with variable from my game.
But when I put this code in Browser - Execute Javascript it doesn't see that variable.
I get this:
How to refer to variables (initiated in C2) in Execute Javascript action of Browser object?
Do you want to just use the value of the variable or do you want to change the variable in the code? If you just need the value then you include it in the string the way you normally include a variable in a string:
Browser: Execute javascript "some javascript code" & playerPoints & "more js code"
Execute javascript "var foo = 'bar';"
Execute javascript "alert(foo)" - >Error foo is undefined
Execute javascript "window['foo'] = 'bar'; "
Execute javascript "alert(foo)" - > bar
[..] Browser: Execute javascript "some javascript code" & playerPoints & "more js code"
[..]
Thank you. This was too easy to figure it by myself
'Execute javascript' just passes whatever you give it to eval(). This can make it hard to write useful sequences as you've noted. We strongly recommend using the Javascript SDK instead.
Develop games in your browser. Powerful, performant & highly capable.
I understand, but sometimes client wants me to input his simple script into my game. Using "Execute Javascript" is very fast in this case.