Create a Wait script with MSC1

Hey all, I’ve got kind of a niche question that you may not have an answer to.
Before we even get started, yes I know that you can import a wait trigger, but I want to be able to control it with Lua.
I’m new to Lua. I’m a native Java programmer, but I have an ETC Mosaic MSC1 Lighting Controller, that can be programmed using Lua. It has an API that is built into the Mosaic Designer software that comes with the device. I’m trying to make a simple wait command, so I can trigger a light, then have a set delay, then have another light trigger.
Researching it a little bit, I found the os.time command. I threw together a quick function in repl.it just to try it out, and it worked. Great right? That’s what I thought too. I tried the code on the controller and got this error:
ACTION Run Script: Failed to run script [string “script”]:2: attempt to index a nil value (global ‘os’)
Here is what the full code looked like in Mosaic Designer:
function wait(seconds)
local start = os.time()
repeat until os.time() > start + seconds - 1
end
 
group1 = get_group_override(1)
group1:set_irgb(255, 255, 0, 0)
wait(2)
group1:set_irgb(255, 0, 255, 0, 2.0, “Linear”)
Again, be warned that I am a native Java programmer, so I might use Java terms to reference things incorrectly. Please correct me if I do, I’m trying to learn.
My take from the error message was either A.) For some reason, the version of Lua built into Mosaic Designer doesn’t have the os class (I think it’s called a namespace in Lua?), or B.) The controller has no operating system, and therefore can’t grab the time from the OS, because an OS doesn’t exist.
Because of this, I read through the API documentation and found the time class/namespace. The only issue is it only returns seconds and restarts when it gets to 59, so my previous code wouldn’t work. My plan was to make a loop that increments a counter every time the second changes. Being a native Java programmer, I first made it in Java, just to get a baseline of what I was working with. You can see that code here. Once I got that working, I transferred it to Lua in Mosaic Designer. This is what the full code in Mosaic Designer looked like:
 
function wait(seconds)
local count = 0
local prevSec = time.get_current_time().second
repeat
local currSec = time.get_current_time().second
if( prevSec ~= currSec ) then
count = count + 1
prevSec = currSec
end
until( count == seconds )
end
 
group1 = get_group_override(1)
group1:set_irgb(255, 255, 0, 0)
wait(2)
group1:set_irgb(255, 0, 255, 0, 2.0, “Linear”)
 
I attempted to run this on the controller, and it crashes every time.
 
I would appreciate it if anyone could help me with this. Thank you in advance!
Parents
  • There is no way to implement timers in LUA directly. Mosaic utilizes the string, math, i/o and bitwise LUA libraries....no access to the OS LUA library. If you need to interact with a timer within your script you can either enqueue a dummy timeline or download one of the wait or watchdog timer modules. When the timer trigger fires you can run a script to call function within your main script.

    A good practice is to create a startup trigger and add your mainscript as the action. This way you can load all of your main functions and initialize variables on boot. All functions loaded on startup can be globally accessed from other helper scripts.

    Good luck!

Reply Children
No Data
Related