[Solved] Set global variable with javascript?

I´m running Gdevelop5 and are wondering if its possible if so how do one set a new value to a global variable trough java script ? tried searching for it for the last few weeks !

Thanks in advanced,
Snappeh!

1 Like

Hi!

Set value of global variable:
runtimeScene.getGame().getVariables().get(“globalVarName”).setNumber(100);
runtimeScene.getGame().getVariables().get(“globalVarName”).setString(“new text”);

Get value of global variable:
var globalVarNumber = runtimeScene.getGame().getVariables().get(“globalVarName”).getAsNumber();
var globalVarString = runtimeScene.getGame().getVariables().get(“globalVarName”).getAsString();
5 Likes

Worked flawlessly !
Thanks for the fast response and help ! <3
Now i can continue with my blockchaingamifications :smiley: !

2 Likes