Hi,
every API is a function, and every function has at least one result, the return code, and maybe other results of the function.
There is a list of return codes here:
https://www.machsupport.com/forum/index.php?topic=40051.0The software test you are applying asks 'Is there an error in the function', if so stop the macro otherwise continue. That is a pretty crude test, there are many reasons that
a function can fail, one of the more common is:
-18 MERROR_NOT_NOW
This means that for whatever reason Mach cannot execute the macro, and that in turn usually results because the screenscript is not executing at that particular moment. If you were to wait,
maybe a few milliseconds and try again then the function would proceed.
There are a few circumstances this error is common. They are characterised by control of the machine as it passes from the main Gcode interpreter to the screenscript,
and an m6 is a prime example. So in this circumstance it may be necessary to use another software test, and even devise a strategy for repeating the API call if it fails.
You may be concerned that ' this seems really bulky and inefficient.', and this further testing makes it worse....but you potentially can save the macro from faulting.
A great deal of effort and expertise in software development is less about 'normal and correct' operation but what happens in a fault condition? Having software to trap an error and ideally
correct it automatically, is the holy grail. You'd certainly hope nuclear launch facilities have robust error trapping routines for example, LOL.
Please keep in mind I do not want to become an expert lua programmer I just want a single usable piece of code to run my tool changer.
You may not want to become an expert and I imagine you'll get your wish, but you will have to be
proficient, and that's nearly as tough.
The alternative is to pay NFS to write it for you,and they will...but at a cost. The expectation that you can write code to enact a tool changer and that it be
as easy as falling off a log is unrealistic.
Craig