Setting a variable from JavaScript is a little different depending on whether you want to have a local or a global variable (apologies for the confusing names; I should've named them 'variables' and 'persistent variables' instead).

If you want to set a 'global' variable, you can use the globalVars object which is a part of the interpreter instance:

The 'local' variables are just a plain JavaScript object that is saved as is for each savegame:

Code:

game.interpreter.runVars["myVar"] = "foo";

The difference between the 'global' vars and the 'local' vars is that a 'local' variable is only available in the current playthrough of a game. All 'local' variables are replaced when you load a savegame, whereas 'global' variables are the same no matter what savegame you are using. The 'global' variables are meant to be used for meta information like "the player has finished the game 2 times."

The 'game' variable you see in the example above is the Game instance created in the index.html file. You will have to obtain a reference to it in your extension by either adding some code to the JavaScript in the index.html file or by listening to the "wse.game.constructor" event on the global bus: