[solved]Lua forgets my objects on load
Posted: Mon Jan 19, 2015 1:39 am
I've actually solved the problem while typing this post, but I've thought I'd still post it so you see how smart am I... oh, and so that it might be of some help to people in future.
So, I've been making tables and assigning a single metatable, which had been defined in the different file, to them like this:
Then I've been putting these tables into saveable glob. - table like this:
Everything works fine from init. But when loading saved game I get error claiming that one of methods is nil. (namely workshop:check())
Solved, by reassigning them their metatables during onload event:
where reset_class_workshop is a function defined in the same file as the metatable.
"glob." before "class_workshop" helps nothing by the way.

So, I've been making tables and assigning a single metatable, which had been defined in the different file, to them like this:
Code: Select all
function glob.class_workshop:new(entity)
workshop=
{entity=entity,
}
setmetatable(workshop,{__index=self})
return workshop
end
Code: Select all
table.insert(glob.workshops,glob.class_workshop:new(entity))
Code: Select all
function modupdate(tick)
if tick%20==0 and glob.active then
for _,workshop in ipairs(glob.workshops) do
workshop:check()
end
end
end
Code: Select all
for _,workshop in pairs(glob.workshops) do
workshop=reset_class_workshop(workshop)
end
Code: Select all
function reset_class_workshop(object)
setmetatable(object,{__index=glob.class_workshop})
return object
end