Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: Tony Bullard on February 04, 2020, 11:03:45 AM
-
I have this function in my Screen Load Script:
----------
function SetSigState (sig,state)
local hSig = mc.mcSignalGetHandle (inst,sig)
mc.mcSignalSetState (hSig,state)
end
----------
It works like this in signal and button scripts:
--Example: local state = GetSigState(mc.OSIG_OUTPUT1)
SetSigState(mc.OSIG_OUTPUT1, 1) --turns on output 1
Or SetSigState(mc.ISIG_INPUT1, 0) set input 1 off
This is M code m111:
function m111()
local inst=mc.mcGetInstance()
mc.mcCntlSetLastError(inst, 'Test m111')
SetSigState(mc.OSIG_OUTPUT2, 0)
end
if (mc.mcInEditor() == 1) then
m111()
end
When I run it in the debugger I get the following error:
Debugging session started in 'C:\Mach4Hobby\Profiles\TBtest\Macros\'.
m111.mcs:6: attempt to call a nil value (global 'SetSigState')
stack traceback:
m111.mcs:6: in function 'm111'
m111.mcs:9: in main chunk
Debugging session completed (traced 6 instructions).
Program completed in 19.11 seconds (pid: 3412).
Any help would be appreciated. Thanks, Tony
-
Someone can correct me if I am wrong but I believe functions declared in the screen load script are only available to gui related activities, buttons, panels, etc. There are two lua chunks running, a gui and a core chunk. I believe you have to create a module either in the Mach4Hobby\Modules directory, like the mcProbing.lua, if you want it available to all profiles or in the profiles modules directory if you want it available only to that profile. You then reference that function within your macro. The mc.********* are available in both chunks but your personal funcs are only available in the chunk it uses. Clear as mud eh?
myFuncs.SetSigState(mc.OSIG_OUTPUT2, 0)
HTH
RT
-
Thank you, RT. And thanks to DazTheGas I did get it to work following his great video.
https://www.youtube.com/watch?v=TMzAT0eb3p0