Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: Bill_O on April 12, 2019, 03:04:36 PM
-
Has anyone made a toggle button that has 3 states?
Ex; On, Off, Auto
I think i can do it with a regular button and use led indicators but it would be nice to just have the button change.
Thanks,
Bill
-
My initial approach would be to use a regular button and on the LeftUp script I would check the label:
If scr.getProperty("MyBtnName","Label")=="ON" then
scr.setProperty("MyBtnName","Label","OFF")
set a register or send a signal and or change the background color or call a function
else If scr.getProperty("MyBtnName","Label")=="OFF" then
scr.setProperty("MyBtnName","Label","AUTO")
set a register or send a signal and or change the background color or call a function
else If scr.getProperty("MyBtnName","Label")=="AUTO" then
scr.setProperty("MyBtnName","Label","ON")
set a register or send a signal and or change the background color or call a function
end
Haven't done any LUA programming lately so you would have to check the above syntax for errors.
HTH
RT
-
rhtuttle's script should work but I would omit the last IF statement and rearrange it. If you reach that point you have checked the other two possibilities. If somehow "MyBtnName" is not one of the choices you would still set a valid value. I would make that default choice "OFF".
If scr.getProperty("MyBtnName","Label")=="OFF" then
scr.setProperty("MyBtnName","Label","AUTO")
--set a register or send a signal and or change the background color or call a function
else If scr.getProperty("MyBtnName","Label")=="AUTO" then
scr.setProperty("MyBtnName","Label","ON")
--set a register or send a signal and or change the background color or call a function
else scr.setProperty("MyBtnName","Label","OFF")
--set a register or send a signal and or change the background color or call a function
end
-
thanks all
i will give it a try
bill
-
This worked great.
I made a register (iRegs0/MistSet)
Then I check the value of the register to change the button.
local inst = mc.mcGetInstance()
local hregmist = mc.mcRegGetHandle(inst, 'iRegs0/MistSet')
local MistNow = mc.mcRegGetValue(hregmist)
if (MistNow == 0) then
scr.SetProperty('btnMistSet', 'Label', 'Mist Auto')
mc.mcRegSetValue(hregmist, 1)
elseif (MistNow == 1) then
scr.SetProperty('btnMistSet', 'Label', 'Mist On')
mc.mcRegSetValue(hregmist, 2)
else
scr.SetProperty('btnMistSet', 'Label', 'Mist Off')
mc.mcRegSetValue(hregmist, 0)
end
Works like a champ and I can use the register values throughout Mach4.
Thanks for the help.
Bill