Page 1 of 1

Crash when saving, can't figure out what is wrong.

Posted: Mon Nov 26, 2012 1:36 pm
by Dregg
Hello.

I have a problem I can't figure out on my own (including using google).
After a certain point in my dungeon, I get this error when I try to save:
Cannot serialize table 'champ' with metatable stack traceback [...lots of text...]

The error appears after I have activated this code:

Code: Select all

function Get400exp()

  champ=party:getChampion(1)
  champ:gainExp(400)
  champ=party:getChampion(2)
  champ:gainExp(400)
  champ=party:getChampion(3)
  champ:gainExp(400)
  champ=party:getChampion(4)
  champ:gainExp(400)

end
The code functions as far as that every champion gets their 400 exp.

I tried using champ=party:getChampion(4):gainExp(400) instead, but that didn't work at all.

Google tells me that others have had the same error, but I can't find any solution to it. Anyone got any idea what is wrong? Obviously it is something to do with the variable "champ", but beyond that...?

Re: Chrash when saving, can't figure out what is wrong.

Posted: Mon Nov 26, 2012 1:46 pm
by Grimwold
A simpler script for distributing the xp would be

Code: Select all

function Get400exp()
  for i = 1,4 do
    party:getChampion(i):gainExp(400)
  end
end
Which would avoid the use of the champ variable altogether...

My guess is it is trying to save the champ variable in the same game file because you did not declare it as local. However it fails because it is not of a data type supported by save games... which can only be numerical or string values, not entities.

e.g.

Code: Select all

local champ = party:getChampion(1)

Re: Chrash when saving, can't figure out what is wrong.

Posted: Mon Nov 26, 2012 1:48 pm
by antti
Yeah, the variables you create inside functions need to be local variables. So instead of champ=party:getChampion(1) you could use local champ=party:getChampion(1). But in this case I would go with Grimwold's suggestion and avoid the variables altogether.

For more details on save game compatibility, check out http://www.grimrock.net/modding/save-ga ... variables/

Re: Chrash when saving, can't figure out what is wrong.

Posted: Mon Nov 26, 2012 4:24 pm
by JohnWordsworth
Ooops, I made this mistake in my room in the Round Robin. Even though I knew about it. So easy just to keep a reference of an object around instead of just the object's ID in a script entity's variable.

Edit: Sorry, just to clarify, it was a slightly different way I created this error. I was keeping track of a spawned entity (so I could destroy() it later), but if you tried to save before destroying it -> BOOM. Crash.

Re: Chrash when saving, can't figure out what is wrong.

Posted: Mon Nov 26, 2012 4:37 pm
by msyblade
The grimwold exp. script above is simple, and universal. You can link to it multiple times, saving some work.

Re: Chrash when saving, can't figure out what is wrong.

Posted: Tue Nov 27, 2012 10:53 am
by Dregg
Thanks, that fixed it. I read the part on saving before, but I didn't really get it then. But now I do.