First baby steps. Trying to set a variable using a popup and then using this variable in commands to write seq's... Need Help.

BECOME PART OF THE COMMUNITY - Sign up here
  • Hi There,

    I would like to combine two scripts I have modified. Both work individualy but when combined they stop working. Noob allert. Might be somthing very simple?

    So, I managed to modify an existing lua script to my liking. The script enables a user to select a fixture type (set a variable) using a popup. The script prints these in the system monitor so I know the variables are indeed defined.

    This is the script:

    local fixture_input = 0

    function Main(display_handle)
        -- Select Fixture Type
        local Fixture_input = PopupInput({title="Fixture Type", caller=display_handle, items={"Spot","Beam","Wash","Led_1","Led_2","Strobe","Blinder","CANCEL"}})
       
        if Fixture_input == 0 then
            Fixture_type = "Spot"
            Printf(""..Fixture_type.."")
           
        elseif Fixture_input == 1 then
            Fixture_type = "Beam"
            Printf(""..Fixture_type.."")
           
        elseif Fixture_input == 2 then
            Fixture_type = "Wash"
            Printf(""..Fixture_type.."")
           
        elseif Fixture_input == 3 then
            Fixture_type = "Led_1"
            Printf(""..Fixture_type.."")
           
        elseif Fixture_input == 4 then
            Fixture_type = "Led_2"
            Printf(""..Fixture_type.."")
           
        elseif Fixture_input == 5 then
            Fixture_type = "Strobe"
            Printf(""..Fixture_type.."")

        elseif Fixture_input == 6 then
            Fixture_type = "Blinder"
            Printf(""..Fixture_type.."")

        elseif Fixture_input == 7 then
            Printf("Plugin execution is Canseled")
            return Main
        end

     end
     return Main

    I also managed to modify an existing scipt to enable me to write some sequences and assign a group, preset and matricks pool item to a recipe in a cue part. I would like to use the variable "Fixture_type" which I have set in the previous mentioned popup script in the script I use to store the sequences. Both scripts work when put in a plugin individualy but if I combine the two in one plugin both stop working.

    Here is the script that writes the sequences:

    local startsequence = 1

    --Here I test if the variable "fixture_type" is working. It is. I remove this when combining the two scripts off-course.
     local Fixture_type = "Blinder"

    --Variables list Sequence name
    local sequence_name = {
        ""..Fixture_type.."_Sym_1/2_Block",
        ""..Fixture_type.."_Sym_2/2_Block",
        ""..Fixture_type.."_Sym_1/2_2Fix",
        ""..Fixture_type.."_Sym_1/2_2Fix",

    }

    --Variables list Matricks pool items
    local matricks_4fixtures_name = {
        "1Fix_1/2_Sym",
        "2Fix_1/2_Sym",
        "3Fix_1/2_Sym",
        "4Fix_1/2_Sym",

    }

    function main()
        Echo("This is a test message")

        --loop
        for i=1, 4 do 

        --commands , store sequence
            Cmd("Store sequence " ..i.." /o")
           
            --store cue and cue parts
            Cmd("Store sequence "..i.." cue 1 part 4 /o")
            Cmd("Store sequence "..i.." cue 1 part 8 /o")
            Cmd("Store sequence "..i.." cue 1 part 12 /o")
            Cmd("Store sequence "..i.." cue 1 part 16 /o")

            --assign, group preset and matricks group of 4 fixtures
            Cmd("Assign group "..Fixture_type.."_4 at sequence "..i.." cue 1 Part 4.1/o")
            Cmd("Assign preset 21."..Fixture_type.."_FG_Bump at sequence "..i.." cue 1 Part 4.1/o")
            Cmd("Assign Matricks "..matricks_4fixtures_name[i].." at sequence "..i.." cue 1 Part 4.1/o")

            --assign, group preset and matricks group of 8 fixtures
            Cmd("Assign group "..Fixture_type.."_8 at sequence "..i.." cue 1 Part 8.1/o")
            Cmd("Assign preset 21."..Fixture_type.."_FG_Bump at sequence "..i.." cue 1 Part 8.1/o")
            Cmd("Assign Matricks 2Fix_1/2_Sym at sequence "..i.." cue 1 Part 8.1/o")

            --assign, group preset and matricks group of 12 fixtures
            Cmd("Assign group "..Fixture_type.."_12 at sequence "..i.." cue 1 Part 12.1/o")
            Cmd("Assign preset 21."..Fixture_type.."_FG_Bump at sequence "..i.." cue 1 Part 12.1/o")
            Cmd("Assign Matricks 3Fix_1/2_Sym at sequence "..i.." cue 1 Part 12.1/o")

            --assign, group preset and matricks group of 16 fixtures
            Cmd("Assign group "..Fixture_type.."_16 at sequence "..i.." cue 1 Part 16.1/o")
            Cmd("Assign preset 21."..Fixture_type.."_FG_Bump at sequence "..i.." cue 1 Part 16.1/o")
            Cmd("Assign Matricks 4Fix_1/2_Sym at sequence "..i.." cue 1 Part 16.1/o")

            Cmd("Label sequence "..i.." "..sequence_name[i].."")

        end
    end

    return main

    My question is: how can I combine the two scripts? I want to be able to use the variable I defined in the first popup script and use this in the second script in which I write the seq's.

    Hope you can help. Please be kind. This is my first week into Lua. :)

    Edited 5 times, last by deepRED.tv (June 13, 2023 at 7:16 PM).

  • Hey,

    Try this code.

    It's based on yours.

    Edited once, last by Ahuramazda (June 14, 2023 at 1:29 PM).

  • This is great stuff. Thank you so much.

    If I understand it correctly I could not have two main functions (or two functions with the same name) in one script? Was that the problem?

    And if you know any good resources to learn Lua for a noob could you please share them?

    Edited once, last by deepRED.tv (June 15, 2023 at 1:12 PM).

  • You're welcome.

    I would better say you can't have several functions with the same name. At the end of the plugin you can return not only main function, but any function you want.

    I think these videos from Jonas can be a good starting point. It's for gMA2, but it's more about Lua rather than gMA2, so you can easily go through the playlist with gMA3.

  • According to that logic my two plugins would work together in one script if I changed the name one of the functions? Tested that and no joy… I would really love to understand what’s going on precisely. Hopefully the course of Jonas will give some answers. I started this but stopped after tut 4 since the syntax for first example, printing “Hello World!” was completely different under ma3. I assumed that this would be the case for a lot of the other exercises. I’ll restart the course if you think it’s good. Thanks again.

    Edited once, last by deepRED.tv (June 15, 2023 at 2:01 PM).

  • For sure you will find the answers there.

    The only difference in these examples are the names of functions.

    In gMA3 to print something to the System monitor, you need to use Echo() function, to print something to Command Line feedback - Printf(), and to execute command - Cmd().

Participate now!

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