scr.ButtonClick(ctrlName)
scr.ButtonDown(ctrlName)
scr.ButtonUp(ctrlName)
Yeah, I put those functions in there because Mach3 had something similar. But I do so regret it! Because it is not the best way to handle this type of thing in Mach4. This is going to be a long one, so sit back with some coffee or something.
The best way is to put the functions that do your actions into the screen load script. There would be one function for each of your current buttons. Then on each button's up script event, simply call the appropriate function. Then in your multi-function button, call all of the functions in the order you wish.
In the screen load script:
function MyButtonFunction1()
--some code to perform the action
end
function MyButtonFunction2()
--some code to perform the action
end
In the button1 up script event:
MyButtonFunction1()
In the button2 up script event:
MyButtonFunction2()
In the multiple function button up script event:
MyButtonFunction1()
MyButtonFunction2()
Basically, you build a tool box of functions in the screen load script. The you just call those functions from any screen element. It just takes a bit more planning but ultimately it is WAY worth it.
But wait, there's more!
What if you might want to call these tool box functions from M code macro scripts as well? This is where LUA modules come into the picture. If you write a module and put your tool box functions in there, then "require" that module in you screen load script and your macro scripts, you can use all of the functions in that module from both screen elements AND macro scripts. The caveat is that global variables cannot be used. However, one can get around that by using Mach registers as your global data storage if you need it.
in a file called MyToolboxModule.lua that is in the Mach Modules directory:
local MyToolbox = {}
function MyToolbox.MyButtonFunction1()
--some code to perform the action
end
function MyToolbox.MyButtonFunction2()
--some code to perform the action
end
return MyToolbox
In your screen load script, put this at the top of the script:
mt = require("MyToolboxModule") -- mt is the namespace by which you access the functions in the module. Short for "My Toolbox". :)
In a file called MyToolbox.mcs in your profile's macros directory:
mt = require("MyToolboxModule") -- mt is the namespace by which you access the functions in the module. Short for "My Toolbox". :)
Now, back to the button scripts themselves. In the button1 up script event:
mt.MyButtonFunction1() -- notice the mt. prefix!
In the button2 up script event:
mt.MyButtonFunction2()
In the multiple function button up script event:
mt.MyButtonFunction1()
mt.MyButtonFunction2()
And finally, a macro script that uses the tool box functions. In a file called m114.msc in the Macros directory:
function m114()
mt.MyButtonFunction1()
mt.MyButtonFunction2()
end
if (mc.mcInEditor() == 1) then
m114()
end
It is a lot to take in, but it does demonstrate the power of the Mach LUA integration. It makes code reuse easy too. Say you have another machine that needs the same functions. Or another screen/profile. All you have to do is move the module code over and "require" it.
Steve