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

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
Dregg
Posts: 2
Joined: Mon Nov 26, 2012 1:22 pm

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

Post 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...?
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

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

Post 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)
User avatar
antti
Posts: 688
Joined: Thu Feb 23, 2012 1:43 pm
Location: Espoo, Finland
Contact:

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

Post 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/
Steven Seagal of gaming industry
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

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

Post 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.
Last edited by JohnWordsworth on Mon Nov 26, 2012 5:41 pm, edited 1 time in total.
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
User avatar
msyblade
Posts: 792
Joined: Fri Oct 12, 2012 4:40 am
Location: New Mexico, USA
Contact:

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

Post by msyblade »

The grimwold exp. script above is simple, and universal. You can link to it multiple times, saving some work.
Currently conspiring with many modders on the "Legends of the Northern Realms"project.

"You have been captured by a psychopathic diety who needs a new plaything to torture."
Hotel Hades
Dregg
Posts: 2
Joined: Mon Nov 26, 2012 1:22 pm

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

Post 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.
Post Reply