Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: cd_edwards on October 26, 2016, 11:45:39 PM
-
function SetRegister(regname, val)
local inst = mc.mcGetInstance()
local hreg = mc.mcRegGetHandle(inst, string.format("iRegs0/%s", regname))
mc.mcRegSetValueString(hreg, val)
if (debug_scp == 1) then
mc.mcCntlSetLastError(inst, "regname = " .. regname .. "val = " .. val)
end
end
I'm attempting to use registers to store script values. This has the effect of having human readable names for variables in a script instead of #var's.
The function above should work and does if there are values already in register "regname". I would like my script to be able to initialize the Register variables and this is proving impossible to implement as the mc.mcRegGetHandle() will not create a variable. it will only return an already existing variable handle. I've looked all over and see no function for creating a Register variable from lua.
or else I'm missing something.
-
Registers can only be created by plugins which are registered to the core and created in a config state, you could use the regfile plugin and create some registers for your scripts to use.
Another possibility is to use the mcProfile commands to create a key on the fly and then delete the key after use.
DazTheGas
-
Registers can only be created by plugins which are registered to the core and created in a config state, you could use the regfile plugin and create some registers for your scripts to use.
This would not allow a script author to distribute his script. I'm not likely to ever come to Australia to create the registers you would need in your regfile plugin in order to use my script. Although I wouldn't mind a free trip.
Another possibility is to use the mcProfile commands to create a key on the fly and then delete the key after use.
DazTheGas
This is possible, but not as user friendly. I basically want to avoid all that crap needed to create a wx window for configuring something. the Reg plugin seemed like a perfect place to create a user friendly, user accessible place to store script variable which can be modified.
-
This is possible, but not as user friendly.
So lets take what code you had
function SetRegister(regname, val)
local inst = mc.mcGetInstance()
local hreg = mc.mcRegGetHandle(inst, string.format("iRegs0/%s", regname))
mc.mcRegSetValueString(hreg, val)
if (debug_scp == 1) then
mc.mcCntlSetLastError(inst, "regname = " .. regname .. "val = " .. val)
end
end
and change it too
local inst = mc.mcGetInstance()
function SetRegister(regname, val)
mc.mcProfileWriteString(inst,"VarReg", regname, val)
end
function GetRegister(regname)
local val = mc.mcProfileGetString(inst, "VarReg", regname, "defVal")
return val
end
-- unload script or appropiate place must have - mc.mcProfileDeleteSection(inst, "VarReg") - to stop mach4 from saving to ini file or they will become persistant.
and for the user
SetRegister("test","testVal")
local teststring = GetRegister("test")
wx.wxMessageBox(teststring)
Looks pretty user friendly to me...................
DazTheGas