Hello Guest it is May 14, 2021, 04:00:13 AM

Author Topic: Function within the “Screen load script” cannot be executed from a macro.  (Read 237 times)

0 Members and 1 Guest are viewing this topic.

Offline Tweakie.CNC

*
  • *
  •  8,706 8,706
  • Super Kitty
    • View Profile
    • Tweakie.CNC
Can anyone please help Coyote with getting this script to execute.

His posting, in German is here; https://www.machsupport.com/forum/index.php?topic=43750.msg281511#msg281511

A translation of his posting…

Morning,
according to the "Mach4 scripting manual" on page 16. When I establish code in the screen load script such as:

-------------------------------------------------- -------------
- Write register
-------------------------------------------------- -------------
function WriteRegister (regname, regvalue)
    local inst = mc.mcGetInstance ()
    local hreg = mc.mcRegGetHandle (inst, string.format ("iRegs0 /% s", regname))
    mc.mcCntlSetLastError (inst, string.format ("iRegs0 /% s", regname)) - for test if i can reach this line
    mc.mcRegSetValueString (hreg, tostring (regvalue))
end

then this function can be executed globally.

I would now like to use this also from the macro:

function m170_setSolderProg (number)
    local inst = mc.mcGetInstance ()
   
    if (mc.mcInEditor () == 0) then
        number = tonumber (number)
        WriteRegister ("SolCon / SolderProg", number)
    else
        local hreg = mc.mcRegGetHandle (inst, "iRegs0 / SolCon / SolderProg")
        mc.mcRegSetValueString (hreg, tostring (number))
    end
   
    SetSolConSolProgOutput (number)
       
    mc.mcCntlSetLastError (inst, string.format ("Solder Program% s updated", number))
end

but it is not executed / found. There is also no error message about it!

I have already entered this into the support of Newfangled, but only received irrelevant phrases as an answer. I have to hold back from writing an angry mail to Trevor W.

I suspect that the place for the function is the wrong one, as in the manual as an example it is only accessed by a screen button.

Does anyone have any advice for me to solve this problem?

Thank you
Coyote
KEEP SAFE !
He needs to write that code in a module and then call it from the macro after instantionating it with a 'require' .
example:

MyRtModule.lua

MyRtModule={}
  MyRtModule.myFunc() return (1) end
  MyRtModule.myFunc2() return(2) end
return MyRtModule

macro:
function m6060
  local rt=require "MyRtModule"
       local rslt=rt.myFunc()
end
Mach4 has a chunk that the GUI runs under and another chunk that runs macros.