Hello Guest it is May 14, 2021, 03:34:18 AM

Author Topic: mcRegGetHandle  (Read 1461 times)

0 Members and 1 Guest are viewing this topic.

mcRegGetHandle
« 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.

Offline DazTheGas

*
  •  753 753
  • DazTheGas
    • View Profile
Re: mcRegGetHandle
« Reply #1 on: October 27, 2016, 02:34:47 AM »
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
« Last Edit: October 27, 2016, 02:39:21 AM by DazTheGas »
Theres always time for a choccy biccy
Re: mcRegGetHandle
« Reply #2 on: October 27, 2016, 08:34:58 AM »
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.


Quote
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.

Offline DazTheGas

*
  •  753 753
  • DazTheGas
    • View Profile
Re: mcRegGetHandle
« Reply #3 on: October 27, 2016, 09:04:37 AM »






Quote
This is possible, but not as user friendly.

So lets take what code you had

Code: [Select]
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


Code: [Select]
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

Code: [Select]
SetRegister("test","testVal")

local teststring = GetRegister("test")
wx.wxMessageBox(teststring)

Looks pretty user friendly to me...................

DazTheGas
Theres always time for a choccy biccy