BECOME PART OF THE COMMUNITY - Sign up here
  • Hi!

    I am a noob with using MA macros. I am looking for a way to create loops, is it possible?

    What I want to achieve is to ask for 3 inputs from the user:

    1, How many fixtures

    2, Start fixture id

    3, Start Sequence number

    And then have the macro create a sequence with 2 cues for each fixture where it turns on and then off it after a specified amount of time. Anyone have any clue if it is possible?

    (I am trying to work around that I can not create single shot phaser with a fixed width in seconds. I want to control the rate of one step but have the other fixed.)

  • I'm not sure how to do it all in a macro, If I think really hard I'm sure you could do something with a recursive macro, but would probably lock the desk up in an infinite loop.

    I'm sure someone will have an ingenious idea, but here is how you might do it in a lua single liner that you can use as a command in a macro to trigger.

    lua"local ti, fc, st, sq;ti = TextInput;fc = ti('How Many Fixtures?');st = ti('Start ID?');sq = ti('Start Seq');for i=0, fc-1 do Cmd(string.format('Fixture %d at Full; Store Seq %d /NC', st+i, sq+i)) end"

    It might look a little scary but here is the same code expanded with comments.

    Code
    local ti = TextInput;                --Store the TextInput() function as ti (just to make it smaller)
    local fc = ti('How Many Fixtures?'); --Ask How many Fixtures
    local st = ti('Start ID?');          -- Ask Starting ID
    local sq = ti('Start Seq');          -- Ask Starting Sequence
    for i=0, fc-1 do                     -- loop based on the fixture count
      Cmd(string.format('Fixture %d at Full; Store Seq %d /NC', st+i, sq+i)) -- << YOUR COMMAND GOES HERE
    end

    So if if you say 10 fixtures starting at FID 1 and SEQ 100 the Commands would be

    Fixture 1 at Full

    Store Seq 100 /NC

    the second would be:

    Fixture 2 at Full

    Store Seq 101 /NC

    Here I'm using the i variable to increment the st (start fixture) and sq (start sequence) so the st+i would evaluate to 1+0 for the first and 1+1 for the second.

    many ways to skin this Schrödinger's cat but this might work.

    I only tested it once, and I've been writing a lot of python and c# so errors are possible.

    :edit

    Oh you can also put any number of commands (within reason) in the for loop, I put two on one line but this could also be written as

    Code
    for i=0, fc-1 do
        Cmd(string.format('Fixture %d at Full', st+i))
        Cmd(string.format('Store Seq %d /NC', sq+i))
    end

    Edited once, last by hoss: More infos and shorter one-liner (March 5, 2021 at 7:34 PM).

  • Thanks! That is great!

    I certainly have to read up on Lua! Are there any documentation regarding available MA functions, states or variables? Like getting fixture ID of a selected group?

    Do you know if there is a way to halt macro execution until the user inputs something into the input box without adding a go command to the next line which require extra user input.

  • There isn't any official LUA documentation yet but I have posted a number of functions here.

    Do you know if there is a way to halt macro execution until the user inputs something into the input box without adding a go command to the next line which require extra user input.

    Outside of changing wait to Go no, but perhaps you can have the lua call a second macro when it's done. Seems like there should be an easier way though.

  • There isn't any official LUA documentation yet but I have posted a number of functions here.


    Outside of changing wait to Go no, but perhaps you can have the lua call a second macro when it's done. Seems like there should be an easier way though.

    Thanks!

    If it is possible to via Lua know what macro it is run from, would a "Go" as the last thing in the lua script advance the macro?

  • Hey look at that, if you set the wait of the lua command to Go then make the last command of the lua Go Macro 1 then it goes.

    As for how to know what macro called the lua script, I'm sure this has come up before and I don't recall the answer but you can use SetUserVar to your advantage and have the macro set a variable with its index, then within the lua use GetVar() and DelVar() to get it's value and delete it.

    You may be moving from one-liner to full plugin though.

  • Hey look at that, if you set the wait of the lua command to Go then make the last command of the lua Go Macro 1 then it goes. Upsers

    As for how to know what macro called the lua script, I'm sure this has come up before and I don't recall the answer but you can use SetUserVar to your advantage and have the macro set a variable with its index, then within the lua use GetVar() and DelVar() to get it's value and delete it.

    You may be moving from one-liner to full plugin though.

    YES, I agree with you..

    Edited once, last by ElderFlash (April 7, 2021 at 5:57 AM).

  • It might look a little scary but here is the same code expanded with comments.

    Yes it does :)
    Thanks for posting the code with comments! that's what I need to learn and make my own code.

    %d get it's value from st+i - but why %d?
    Could I add more and do something like: ('Fixture %d at %x', st+i, xx+i)) with result %d=st+i and %x=xx+i ?

  • %d get it's value from st+i - but why %d?

    from the Lua manual :

    The function string.format is a powerful tool when formatting strings, typically for output. It returns a formatted version of its variable number of arguments following the description given by its first argument, the so-called format string. The format string has rules similar to those of the printf function of standard C: It is composed of regular text and directives, which control where and how each argument must be placed in the formatted string. A simple directive is the character `%´ plus a letter that tells how to format the argument: `d´ for a decimal number, `x´ for hexadecimal, `o´ for octal, `f´ for a floating-point number, `s´ for strings, plus other variants. Between the `%´ and the letter, a directive can include other options, which control the details of the format, such as the number of decimal digits of a floating-point number:

    Code
    print(string.format("pi = %.4f", PI)) --> pi = 3.1416
    
    d = 5; m = 11; y = 1990 
    print(string.format("%02d/%02d/%04d", d, m, y)) --> 05/11/1990
    
    tag, title = "h1", "a title"
    print(string.format("<%s>%s</%s>", tag, title, tag)) --> <h1>a title</h1>

    In the first example, the %.4f means a floating-point number with four digits after the decimal point. In the second example, the %02d means a decimal number (`d´), with at least two digits and zero padding; the directive %2d, without the zero, would use blanks for padding. For a complete description of those directives, see the Lua reference manual. Or, better yet, see a C manual, as Lua calls the standard C libraries to do the hard work here.

Participate now!

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