local NextSpindleRange = mc.mcCntlGetLocalVar(inst, hVars, mc.SV_P)
That line pulls the P word from the G code line. It will be hard to debug in the editor since you can't really execute a G code line. There are also these related functions available:
flag, rc = mc.mcCntlGetLocalVarFlag(number inst, number hVars, number varNumber) -- This one tels you if the G code word was set on the G code line. e.g. "M101 P1"
local flag
flag, rc = mc.mcCntlGetLocalVarFlag(inst, hVars, mc.SV_P) -- flag would equal 1 because P1 was specified on the G code line.
flag, rc = mc.mcCntlGetLocalVarFlag(inst, hVars, mc.SV_Q) -- flag would equal 0 because Q was specified on the G code line.
comment, rc = mc.mcCntlGetLocalComment(number inst, number hVars) -- retrieve the comment on the G code line that contains the M code.
As I said earlier, it is hard to debug these things because no G code line has been executed when debugging in the script editor. So I put in a little helper API function that will simulate it.
hVars, rc = mc.mcCntlCreateLocalVars(number inst, string gCodeLine)
It would be used in the function call stub like this:
if (mc.mcInEditor() == 1) then
-- The function call stub is only ever executed when in the editor debugging, so it is safe to leave this in for testing.
local inst = mc.mcGetInstance()
local hVars, rc
hVars, rc = mc.mcCntlCreateLocalVars(number inst, string gCodeLine)
M101(hVars)
end
There are caveats to passung G code words to M codes. One is you can't use the M word as a variable. You can use a word more than once. And finally, the M code that takes variables has to be the only thing on the line.
Steve