Hello Guest it is March 28, 2024, 11:56:15 AM

Author Topic: Mach4 How to Change #Variable value from LUA  (Read 4210 times)

0 Members and 1 Guest are viewing this topic.

Offline Dan13

*
  •  1,208 1,208
    • View Profile
    • DY Engineering
Mach4 How to Change #Variable value from LUA
« on: May 24, 2015, 03:00:24 PM »
Trying to set a #Variable value by a script in a button. As per the Mach4 Scripting Manual, I have created this function in the ScreenLoad Script:

function WriteRegister(regname, regvalue)
  local inst = mc.mcGetInstance()
  local hreg = mc.mcRegGetHandle(inst, string.format("#Variables/%s", regname))
  mc.mcRegSetValueString(hreg, tostring(regvalue))
end

And in the buttin script I have this:

WriteRegister("#1", 15)

However, clicking the button doesn't change the value of #1 to 15. Following the example above, tried change iRegs0 and Sim0 register values and it worked fine, but not with #Variables. How should it be done?

Dan

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: Mach4 How to Change #Variable value from LUA
« Reply #1 on: May 24, 2015, 03:33:04 PM »
I had the same problem

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: Mach4 How to Change #Variable value from LUA
« Reply #2 on: May 24, 2015, 06:50:07 PM »
you need to use the setvar, and getvar funcs
fun times

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: Mach4 How to Change #Variable value from LUA
« Reply #3 on: May 24, 2015, 09:23:43 PM »
I had problem`s getting the bit above 4.4 to work some of the stuff in the manual does not work or the editing is out

this is whats mean to be in the button

regval = GetRegister("Test1")
wx.wxMessageBox(regval)

and this is the bit that goes in the screen load script

function GetRegister(regname)
local inst = mc.mcGetInstance()
local hreg = mc.mcRegGetHandle(inst, string.format("iRegs0/%s", regname))
return mc.mcRegGetValueString(hreg)
end

what you are trying is what comes after whats above that needs to go in first then when you write to then you use the button to read what you sent its the value of (regval = GetRegister("Test1") value of Test1, puts out wx.wxMessageBox(regval) the value of it.

I think that correct if wrong popabear will say

Offline Dan13

*
  •  1,208 1,208
    • View Profile
    • DY Engineering
Re: Mach4 How to Change #Variable value from LUA
« Reply #4 on: May 25, 2015, 04:08:59 AM »
Scott, can you be more specific? Or is this documented anywhere?

Daniel, hardly understood a word of what you said.

Dan

Offline Dan13

*
  •  1,208 1,208
    • View Profile
    • DY Engineering
Re: Mach4 How to Change #Variable value from LUA
« Reply #5 on: May 25, 2015, 04:38:37 AM »
OK, this worked:

local inst = mc.mcGetInstance()
local param = 1 -- variable #1
local val = 12
mc.mcCntlSetPoundVar(inst, param, val)

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: Mach4 How to Change #Variable value from LUA
« Reply #6 on: May 25, 2015, 08:52:44 AM »
mc.mcCntlSetPoundVar(inst, param, val)
local val = mc.mcCntlGetPoundVar(inst, param)

See the down and dirty in the tool box
fun times