Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: Dan13 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
-
I had the same problem
-
you need to use the setvar, and getvar funcs
-
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
-
Scott, can you be more specific? Or is this documented anywhere?
Daniel, hardly understood a word of what you said.
Dan
-
OK, this worked:
local inst = mc.mcGetInstance()
local param = 1 -- variable #1
local val = 12
mc.mcCntlSetPoundVar(inst, param, val)
-
mc.mcCntlSetPoundVar(inst, param, val)
local val = mc.mcCntlGetPoundVar(inst, param)
See the down and dirty in the tool box