Hello Guest it is April 17, 2024, 11:18:23 PM

Author Topic: lua code help please  (Read 1357 times)

0 Members and 1 Guest are viewing this topic.

lua code help please
« on: April 16, 2018, 07:11:59 AM »
mach 4
in attachments i send a picture, i have 4 buttons, i need script:

if I click one of this four = this one on, the others = off
if i click second of this four = this one on = the others =off
and for 3th and 4th the same

please help me I dont have mind, and this is my work
Re: lua code help please
« Reply #1 on: April 16, 2018, 08:33:40 AM »
What do you want to turn on?  An output?
Chad Byrd
Re: lua code help please
« Reply #2 on: April 16, 2018, 08:37:46 AM »
inverter (multi-function)
four outputs

MI3/MI4/MI5/MI6

1st button  -- on/off/off/off
2nd button -- off/on/off/off
3th button  -- off/off/on/off
4th button  -- off/off/off/on


i need this configuration
« Last Edit: April 16, 2018, 08:40:37 AM by michael123 »
Re: lua code help please
« Reply #3 on: April 16, 2018, 09:01:20 AM »
Okay,
So you need to put this script inside each of your buttons.  Put it in the "Clicked Script", that will be fine.
You will have to change the output numbers to meet your need.  I used 5-8 for this example.
This is a quick way to accomplish what you want. 


--Turn on Output 5 turn off Outputs 6, 7, and 8.
local inst = mc.mcGetInstance()
local Output5 = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT5)
local Output6 = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT6)
local Output7 = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT7)
local Output8 = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT8)

mc.mcSignalSetState(Output5, 1)  --On
mc.mcSignalSetState(Output6, 0)  --Off
mc.mcSignalSetState(Output7, 0)  --Off
mc.mcSignalSetState(Output8, 0)  --Off

You will have to go into each button and change the SetState to 0 or 1 depending on which output you want to turn on with each button.
Chad Byrd

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: lua code help please
« Reply #4 on: April 26, 2018, 11:47:36 PM »
Another way to do it would be to build a function in the screen load script and then call that function passing a parameter for the output to turn on in each of the buttons. I try to build functions then have the buttons just run those functions especially when the buttons work together as in this example. It makes screen edits easier and you can spend the time you would spend scripting buttons making the function more robust or adding features. In the function below it doesn't take much imagination to see where you could programmatically change the state of just as many buttons as the outputs your controlling (assuming you named the buttons something that would work). For the example below my buttons would be named TurnOn5, TurnOn6, etc. Try it and see.


Code: [Select]
-- button script
TurnOneOn(5) --5-8


function TurnOneOn(OutToTurnOn)
local firstoutput = mc.OSIG_OUTPUT5
for v = 5, 8, 1 do --Start, End Increment
local hReg, rc = mc.mcSignalGetHandle(inst, firstoutput)
if (rc == 0) then

if (v == OutToTurnOn) then
rc = mc.mcSignalSetState(hReg, 1)
else
rc = mc.mcSignalSetState(hReg, 0)
end
if (rc ~= 0) then
mc.mcCntlSetLastError(mcErrorCheck[rc]) --Get the returned error string
break
end
firstoutput = (firstoutput + 1)

else
mc.mcCntlSetLastError(mcErrorCheck[rc]) --Get the returned error string
break
end
end
end
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!