How to get value of global variable with JS event?
Tried runtimeScene.getGame().getVariables().get().Score i get undefined.
How to get value of global variable with JS event?
Tried runtimeScene.getGame().getVariables().get().Score i get undefined.
You should read this from the “gdjs.VariablesContainer” documentation :
get ( name ) :
Parameters:
—>name String ( The variable’s name )
So, it should be:
runtimeScene.getGame().getVariables().get("MyVar")
Note that this return a “gdjs.Variable” instance, to get the value of the variable, for example for a number variable:
runtimeScene.getGame().getVariables().get("MyVar").getAsNumber()
Thank you.