I am trying to make my plugin dynamic so I can easily add more types of scrolls to the scroll table, and then next time the plugin will have that type added. However I found if it was saving and loading the table, any changes I made in the file didn't affect it and it would load the table again without those additions.
What I did to get around that was have it save the table on another name, and then run comparisons between the tables and then correct for it. I was curious about anyone's comments if there is a better way to do this.
Now if I want to run the plugin again without it having the part of ccc I can just change the table to be:
And the plugin will no longer have the ccc reference but will have the values right for the ones left.
Comments please.
[EDIT] Changed from quote tags to code tags.
What I did to get around that was have it save the table on another name, and then run comparisons between the tables and then correct for it. I was curious about anyone's comments if there is a better way to do this.
function OnPluginInstall ()
--[[
scrolls = {
{"jpct", "jogloran's portal of cheaper travel"},
{"ccc", "chrenedict's corporeal covering"},
{"tpa", "transcendent pneumatic alleviator"}
}
]]--
assert (loadstring (GetVariable ("scrolls_saved") or "")) ()
if scrolls_saved ~= nil then
for i, v in ipairs (scrolls) do
if scrolls_saved[i] ~= nil and scrolls[i][1] == scrolls_saved[i][1] then
scrolls[i] = scrolls_saved[i]
else
for k, v in ipairs (scrolls_saved) do
if scrolls[i][1] == scrolls_saved[k][1] then
scrolls[i] = scrolls_saved[k]
end
end
end
end --for
end
DebugNote("Loading...")
end -- function OnPluginInstall
-- on saving state, convert Lua table back into string variable
-- save_simple is for simple tables that do not have cycles (self-reference)
-- or refer to other tables
function OnPluginSaveState ()
DebugNote("SaveState:Saving...")
SetVariable ("scrolls_saved",
"scrolls_saved = " .. serialize.save_simple (scrolls))
end -- function OnPluginSaveState
Now if I want to run the plugin again without it having the part of ccc I can just change the table to be:
scrolls = {
{"jpct", "jogloran's portal of cheaper travel"},
{"tpa", "transcendent pneumatic alleviator"}
}
And the plugin will no longer have the ccc reference but will have the values right for the ones left.
Comments please.
[EDIT] Changed from quote tags to code tags.