Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: rrc1962 on May 26, 2016, 11:48:00 PM
-
I'm writing to the ini file for saving persistent DRO's and it works great. I'm setting up some check boxes using toggle buttons and images and I'm trying to save the state of the button to the ini file on screen unload. It doesn't work. It should be saving the button state in the Preferences section, but it's not. I inserted a message box and it is capturing the button state, just not writing it to the ini. Code is below. What am I doing wrong?
inst = mc.mcGetInstance()
val = scr.GetProperty('togCheck1', 'Button State')
mc.mcProfileWriteString(inst, "Preferences", "togCheck1", string.format (val))
-
have you tried tostring(val)
Im away from a computer so cant check myself.
DazTheGas
-
4.4 in the scripting manual
-
I'm pretty much doing exactly what's in the scripting manual, but I changed the code to match the manual exactly and still nothing. Is it possible that mc.mcProfileWriteString in the unload script is trying to write to the ini file while another process is writing to it? Or will one wait fro the other to finish?
-
You are not actually writing to the file, you are writing to internal registers, the last thing mach does before closing is to write these registers to the machine.ini
DazTheGas
-
So what I did is I put this code in the button Down Script...
inst = mc.mcGetInstance()
mc.mcProfileWriteString(inst, "Registers", "togCheck1", "1")
And this code in the Button Up script....
inst = mc.mcGetInstance()
mc.mcProfileWriteString(inst, "Registers", "togCheck1", "0")
And this works. Must some sort of conflict with doing this in the unload script. Maybe Mach is writing the ini file before the unload script runs.
-
Beet me to it but this works too.
local inst = mc.mcGetInstance()
val = scr.GetProperty('togCheck1', 'Button State')
mc.mcProfileWriteString(inst, "Preferences", "togCheck1", tostring(val))
DazTheGas
-
Must some sort of conflict with doing this in the unload script. Maybe Mach is writing the ini file before the unload script runs.
The button has been destroyed by the time the unload script runs so it is out of scope. You can't get the state if it isn't there. That is why I populate persistants in the first run of PLC script.
-
So saving the state of a button can only be done in one of the buttons event scripts, correct? There are plenty of outputs that will never be used. I suppose I could tie the button to an output and get the state of the output on unload. Are the outputs readable in an unload script?
-
The state of your button is getting written to the machine.ini on clicking it with the code you had earlier, thats all you need.
DazTheGas
-
I was thinking more along the lines of a way to do it all in the unload script.
-
I really cant see the point when it can be done as you go with the button? but anyway you could use the registry plugin and save the states to registry values.
DazTheGas