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.
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.
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
don't forget to declare your temporary lua variables as local
Oops forgot thanks.
That’s awesome thank you.
And yes good point about doubling, I should have not used 2 in my example :p
Display MoreAssuming 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.
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?
Anything inside of lua'' is treated as lua code. so SetVar(), GetVar(), UserVars(), and others are all lua functions. Early on I documented as many as I could before getting busy again, probably mistakes in there but these ones are somewhat simple to use.
Ok I’ll have to do some digging thanks. I’ve never seen SetVar in lua before. Normally you’d just define a variable and use it.
SetVar and GetVar are special functions of the grandMA3 Lua API, enabling Lua interaction with grandMA3 Commandline $variables.
Ah lovely
Don’t have an account yet? Register yourself now and be a part of our community!