Adding and subtracting variables with scripts

i put this in as a test (lost level being the name of my var with 2 as its id) and it is not working
and advice on where i can learn more about using variables in scripts becuase i wanna go on to do some more advanced operations

1654706694072.png
$gameVariables.value just gives you the actual value of that variable. To set it to a particular value, you need to use $gameVariables.setValue. So, for example, $gameVariables.setValue(2, 10) will set variable 2 to the value of 10.

To add to and subtract from the variable, you could use
JavaScript:
$gameVariables.setValue(2, $gameVariables.value(3) - 10)
which will set variable 2 = variable 3 - 10.

Note that these operations can all be done using a couple of event commands (without scripting), unless you have something different in mind.

You can see a list of MV's script calls here: https://forums.rpgmakerweb.com/index.php?threads/rpg-maker-mv-mz-script-call-list.46456/

Original thread: https://forums.rpgmakerweb.com/threads/adding-and-subtracting-variables-with-scripts.148344/