Lua math in command line

BECOME PART OF THE COMMUNITY - Sign up here
  • 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! (November 27, 2020 at 2:58 PM).

  • 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?

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!