Lua math in command line

  • Because there are much more cleverer people than me here.


    Does anyone have the quick command line lua to take a variable and multiple it by say 2 and replace the variable with the new value?


    like X= $variable, X = X*2, $variable=X


    Thank you muchly.

  • Assuming the number in question is stored in UserVar "INPUT" this will multiply that number by 2 and put it back in the INPUT UserVar:


    lua'local x=UserVars();SetVar(x, "INPUT", GetVar(x, "INPUT") * 2)'


    Someone probably knows a simpler way though.


    If you want to ask for the multiplier perhaps something like this:


    lua'local x=UserVars();local v="INPUT"local m = tonumber(TextInput("Multipier",1));SetVar(x, v, GetVar(x, v) * m)'


    This will popup a text window where the user can enter a number, it will default to 1, only because we can. It will error out if you do not enter a number or enter text.

    Edited 2 times, last by hoss: Added input example. always LOCAL! ().

  • for the example of doubling a value, you could get away with regular commandline addition:


    SetUserVar myVar $myVar$myVar


    hoss don't forget to declare your temporary lua variables as local to avoid polluting the environment _G

  • Small question... SetVar is not actually a MA3 command, so why is SetVar and GetVar being used in this line?
    How does the console translate that to SetUserVar and GetUserVar?