Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: Blacksmith on July 14, 2015, 07:22:48 AM

Title: need help with script
Post by: Blacksmith on July 14, 2015, 07:22:48 AM


i have this code in the signal script,

if (sig == mc.ISIG_INPUT1) and (state == 1) then
local inst = mc.mcGetInstance()
mc.mcCntlCycleStart(inst)
end

but what if i have two inputs

something like this  : 

 if ((sig == mc.ISIG_INPUT1) and (state == 1)) and ((sig == mc.ISIG_INPUT10) and (state == 1))
local inst = mc.mcGetInstance()
mc.mcCntlCycleStart(inst)
end


how do i do that ?
Title: Re: need help with script
Post by: poppabear on July 14, 2015, 02:23:27 PM
Code: [Select]
local Input1 = 0;
local Input10 = 0;
local hSig = 0;

hSig = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT1);
Input1 = mc.mcSignalGetState(hSig);

hSig = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT10);
Input10 = mc.mcSignalGetState(hSig);

if (Input1 and Input10 and (state ==1)) then
    local inst = mc.mcGetInstance();
    mc.mcCntlCycleStart(inst);
end

--Scott
Title: Re: need help with script
Post by: Blacksmith on July 15, 2015, 09:14:50 AM
thank you its working :))
Title: Re: need help with script
Post by: Blacksmith on July 15, 2015, 10:06:40 AM
BTW , can i use this method in a sig table also ?
Title: Re: need help with script
Post by: dude1 on July 15, 2015, 05:02:30 PM
yes but it`s a little bit different look in the mach 4 scripting manual it under manuals on mach web site
Title: Re: need help with script
Post by: Tinker Smurf on August 31, 2015, 03:50:18 PM
Found out that the piece of script from poppabear isn't working as intended. If you only activate one of either inputs the task wil already be executed.
the correct way to do this is.

local Input1 = 0;
local Input10 = 0;
local hSig = 0;

hSig = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT1);
Input1 = mc.mcSignalGetState(hSig);

hSig = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT10);
Input10 = mc.mcSignalGetState(hSig);

if ((Input1 == 1) and (Input10 ==1)) then
    local inst = mc.mcGetInstance();
    mc.mcCntlCycleStart(inst);
end


I hope it is to some use.

Marco.
end