Hi,
I came across this thread and in particular reply 5
http://www.gammon.com.au/forum/?id=10980&reply=5#reply5
I thought this a neat solution for what I wanted based on some of the questions I had raised previously. I admit it might be slightly more complicated solution than what I needed it for right now, however, I like to dive in feet first. Also it will make the code easier to upgrade later.
In my plugin i didn't like that I was repeatedly calling GetVariable and SetVariable. The code works as intended.
Have successfully tested some examples using Nicks advise http://www.gammon.com.au/forum/?id=12844&reply=5#reply5 also http://www.gammon.com.au/forum/?id=6030&reply=11#reply11
I then went ahead and implemented the above tvar.lua.
I've hit a wall. I can create the table, and checking the state file and see the table/variable is serialized etc. I can print the table and it's elements.
However, once it's initially set up, I cannot reassign new values to the "elements". I know it's most likely down to my not fully understanding how tables work. I thought I had resolved this last night before going to bed but by the next morning the solution escaped me!
In terms of the plugin setup everything is working. All requires etc as it should be.
snippet code, run when plugin loads or settings intialised:
As extra info I use this for onpluginsave. Is this the correct method?
I also thought this would work to clear the table but it doesn't
Dak
I came across this thread and in particular reply 5
http://www.gammon.com.au/forum/?id=10980&reply=5#reply5
I thought this a neat solution for what I wanted based on some of the questions I had raised previously. I admit it might be slightly more complicated solution than what I needed it for right now, however, I like to dive in feet first. Also it will make the code easier to upgrade later.
In my plugin i didn't like that I was repeatedly calling GetVariable and SetVariable. The code works as intended.
Have successfully tested some examples using Nicks advise http://www.gammon.com.au/forum/?id=12844&reply=5#reply5 also http://www.gammon.com.au/forum/?id=6030&reply=11#reply11
I then went ahead and implemented the above tvar.lua.
I've hit a wall. I can create the table, and checking the state file and see the table/variable is serialized etc. I can print the table and it's elements.
However, once it's initially set up, I cannot reassign new values to the "elements". I know it's most likely down to my not fully understanding how tables work. I thought I had resolved this last night before going to bed but by the next morning the solution escaped me!
In terms of the plugin setup everything is working. All requires etc as it should be.
snippet code, run when plugin loads or settings intialised:
function initPots()
var.potVars = var.potVars or {}
local next = next
initVars = {}
var.initVars = {heal = "martini", healnum = 5, threshold = 5}
if next (var.potVars) ~= nil then
if clrNum == "true" then -- code to determine whether to just initalise healnum
for k,v in pairs (var.potVars) do
if string.sub(string.lower(k),5,7) == "num" then
v = 0 -- this worked but doing var.potVars.k = 0 didn't.
print(k,v)
--print ("i ran")
end --if
end --for
end --if
else
var.potVars = var.initVars
end --if
var.potVars.heal = "test" -- this does not assign a new value.
print(var.potVars.heal) --shows default value.
end --initPots
As extra info I use this for onpluginsave. Is this the correct method?
function savePots()
var.potVars = var.potVars
end --savePots
I also thought this would work to clear the table but it doesn't
var.potVars = nil
Dak