Finally got it. The return data type is a number, which is why 1 didn't equal 1. The other issue was this....
mc.mcSignalSetState(mc.OSIG_OUTPUT1, true)
I thought that when I changed the if statement to evaluate 1 instead of '1', it was crashing M4. What it was doing was finally working correctly. mc.mcSignalSetState needs the handle to the output, not the output. That was crashing M4. Don't know how I missed that one. I've written plenty of macros to manipulate outputs.
Here's the code. When you call this M code, like M162 A3 B1, it turns on output 3. M162 A3 B0 would turn it off. I only use outputs 0 - 20 but the table could be expanded to include all of them.
function m162(args)
inst = mc.mcGetInstance()
---------------------------------------------------------------
-- A = OutputNumber, B = OutputState
---------------------------------------------------------------
OutputTable = {
[0] = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT0),
[1] = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT1),
[2] = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT2),
[3] = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT3),
[4] = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT4),
[5] = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT5),
[6] = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT6),
[7] = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT7),
[8] = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT8),
[9] = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT9),
[10] = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT10),
[11] = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT11),
[12] = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT12),
[13] = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT13),
[14] = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT14),
[15] = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT15),
[16] = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT16),
[17] = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT17),
[18] = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT18),
[19] = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT19),
[20] = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT20)
}
if (args ~= nil) then
OutputNumber = mc.mcCntlGetLocalVar(inst, args, mc.SV_A)
OutputState = mc.mcCntlGetLocalVar(inst, args, mc.SV_B)
if (OutputState == 1) then
mc.mcSignalSetState(OutputTable[OutputNumber], true)
else
mc.mcSignalSetState(OutputTable[OutputNumber], false)
end
else
mc.mcCntlSetLastError(inst, 'No Arguments Found')
end
end
if (mc.mcInEditor() == 1) then
m162(nil)
end