Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: irwincalkins on September 25, 2024, 02:49:28 AM
-
Any Lua scripting experts here, that are experienced with Mach4?
I (G-code/Lua/Mach4 beginner, but experienced programmer) am facing the following issue:
I'm trying to write a macro for Mach4Hobby for some M code, say, M100. I've had a look at the exemplary m162.mcs in Profiles/Mach4Mill/Macros/ folder and I came across this in line 10
function m162(hParam) --The param is a P value called from Gcode. M162P3 for example.
which led me to believe that I can specify parameters that are passed to my macros with a "P", following my M-code (after some more googling this seems to be the case). Now I've written the following for M100 into m100.mcs:
local inst = mc.mcGetInstance()
function m100(hParam)
if (hParam ~= nil) then
mc.mcCntlLog(inst, string.format("hParam %d", hParam), "",0)
end
end
From what I inferred from m162.mcs, if I add a line like
M100P10
to my MDI, the called M100-macro should get a (numeric) 10 as an argument and this should now show up in the log. However, when I run it, the output is always some random number, like "hParam 466550640", no matter what value I add as a "P value", even if I don't pass a parameter at all (i.e., just putting "M100"). Note that I also tried variations like "M100 P10", "M100 10".
There is apparently an argument passed to the macro (because it is never NIL, even if I skip the P value in the MDI), but it seems like is contains the wrong value, or some handle/reference or whatever. Why is that? Is this not how it's supposed to be used? If not, what is a P value and how can I get a parameter into my macro from G-code/MDI? Unfortunately, I cannot find any documentation on that, but maybe I just missed it?
(Using Mach4Hobby 4.2.0.5036)
-
check this out: https://www.machsupport.com/forum/index.php?topic=28528.msg200283#msg200283