434
« on: August 16, 2019, 12:48:18 PM »
wait(1) is the main problem. At least that is what the error log said. In order to use it, it must be defined ABOVE the code from which you want to call it. It looks like you were nesting that wait function inside another function? Possibly the m110() function?
This should work:
-- Dust Collector button script
-- M110/M111 Output 50 signal 1100
function wait(seconds)
local start = os.time()
repeat until os.time() > start + seconds
end
function m110()
inst = mc.mcGetInstance()
local hSig, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT50)
mc.mcSignalSetState(hSig, 1)
wait(1)
mc.mcSignalSetState(hSig, 0)
end --end function m110
Also, you may run into a even more hard to deal with problem if several macro scripts define a wait() function. Only the LAST loaded wait() function will be used! Now which one will it be? The answer is "You don't know!"
The best way to use common functions that are available to ALL macro scripts is by using modules.
But you don't even need to define the wait() function or use modules for this. Fortunately, we have LUA with wxWidgets bindings and you can use its' wx.wxMilliSleep() function. If you want to wait 1 second, then do wx.wxMilliSleep(1000). Half a second is 500, etc...
Steve