I'm having a rough time with an attempt at a global variable in a plugin as well. Trying to follow the various instructions in the forum closely, I'm using this:
<![CDATA[
require "serialize"
ch = {}
-- Some functions that assign values to ch items
-- In desperation I even added
SetVariable ("ch", "ch = " .. serialize.save_simple (ch))
-- to one that I knew was setting values to ensure that SetVariable was being called
-- -----------------------------------------------------------------
-- Built-in callbacks
-- -----------------------------------------------------------------
function OnPluginInstall ()
assert (loadstring (GetVariable ("ch") or "")) ()
if ch.HP == nil then
ColourNote ("red", "", "Initializing ch")
ch = {
name = "Unknown",
race = "Unknown",
class = "Unknown",
hasMagic = false,
isFighting = false,
align = "Neutral",
HP = { cur = 0, total = 100, },
MA = { cur = 0, total = 0, },
stats = { STR = 1, AGI = 1, INT = 1, HEA = 1, WIS = 1, CHA = 1, }
}
else
ColourNote ("yellow", "", "Loading " .. ch.name)
end
end
function OnPluginSaveState ()
SetVariable ("ch", "ch = " .. serialize.save_simple (ch))
end
Yet every time I load the world I see the red message that the ch variable is being initialized. Can someone educate me on where I'm going wrong? |