Math with variables

BECOME PART OF THE COMMUNITY - Sign up here
  • Perhaps the User Formerly Known as Glad might chime in here.


    I have a macro that I'm attempting to convert to 3, from 2. I call it the Concurrent Arrival Fan, and it's a trick a much older LD showed me years ago. He did it manually, I made a macro. Basically, it aligns fade opposite delay to create an interesting movement. Here is the old MA2 macro:


    Code
    Macro "World Is Selection"
    SetUserVar $MinFade = ("Minimum fade time, at least 1")
    SetUserVar $MaxFade = ("Maximum fade time)
    PresetType "POSITION" At Fade $MaxFade Thru $MinFade
    SetUserVar $MaxDelay = $MaxFade
    $FORMULA "$MaxDelay=$MaxFade-$MinFade"; CALCULATE
    PresetType "POSITION" At Delay 0 Thru $MaxDelay
    World 1

    Obviously this used glad's Intellivars, which he no longer supports for the MA3. I'm aware that I'll have to change a few other things once I figure this out.


    I believe, however, that this simple math can be done natively within the macros now, because you can add integers. Unless I'm reading the help files wrongly, there is no direct way to subtract. However, there is the old (and silly) trick of making one integer negative and adding those. In fact, MA uses this example in their help file.

    I tried the following:

    Code
    SetUserVariable "number" 1
    SetUserVariable "number" - "number"

    My thinking was that this would turn the integer negative. Instead, it erased the value, setting it to nil.


    How could I turn a given (integer) number negative? Or am I going to have to pay some Lua developer to write me add / subtract / multiply / divide scripts? I am not "that kind" of programmer.

    Craig Rutherford

    Blueshift Design

  • This works for me:

    • SetUserVariable mynum1 5
    • SetUserVariable mynum2 3
    • SetUserVariable mysum -$mynum2$mynum1
      • mysum is set to 2 (-3 + 5)
    • SetUserVariable mysum -$mynum1$mynum2
      • mysum is set to -2 (-5 + 3)
  • At the moment, just like in gMA2, you’ll still need a pinch of Lua to subtract variable values.

    The only variable math that’s possible directly is, addition.

    I see your MaxDelay variable is the difference between MaxFade & MinFade.

    This is the only reason I used Lua.

    Perhaps, when other basic arithmetics are possible with variables, we can get rid of this Lua line.


    Or, you could do it like you did it in gMA2, loading a Lua function into the showfile that allows for these calculations.

    And then, simplify the line.


    In the end, the result will still be the same.

  • Luke I see in your macro that you added a line to change the string to an integer. Is it not possible to accept an integer as user input because of the quotes? Will user input always be a string that must be converted if you want to use it as an integer?


    Not to change the topic but since it's related, does anyone know if / when conditionals are coming back to macros? Or will this need to be Lua?

    Craig Rutherford

    Blueshift Design

    Edited once, last by blueshiftdesign ().

Participate now!

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