[Solved] Save game blowing up with my custom dungeon

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: [Solved] Save game blowing up with my custom dungeon

Post by minmay »

"Tells you nothing"? It tells you EXACTLY what went wrong: you have a field that can't be serialized.

As it happens, Lark didn't read this page, and posted multiple broken scripts to this forum. In the case of this script, all of the variables are "global" to the script entity so as soon as they are assigned they become permanent fields. Which, of course, will break saving since it includes an unserializable variable: a GameObject reference.
Here is a fixed version.

Code: Select all

do
local num = 0
local bad = 2
while bad > 0 do
  num = num + 1
  local obj = findEntity("dungeon_wall_lantern_" .. num)
  if obj ~= nil then
    local val = obj:getWorldPosition()
    val[2] = val[2] + .7
    local ix = (3 - (obj.facing % 2) * 2)
    local dx, dy = getForward(obj.facing)
    val[ix] = val[ix] + .21 * (dx - dy)
    obj:setWorldPosition(val)
  else
    bad = bad - 1
    end
  end
end
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
Thorham
Posts: 80
Joined: Sat May 04, 2013 5:12 pm

Re: [Solved] Save game blowing up with my custom dungeon

Post by Thorham »

minmay wrote:Which, of course, will break saving since it includes an unserializable variable: a GameObject reference.
That sucks, especially because this doesn't have to be serialized. The object's data is stored already, after all.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: [Solved] Save game blowing up with my custom dungeon

Post by minmay »

The reference would have to be serialized.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
Thorham
Posts: 80
Joined: Sat May 04, 2013 5:12 pm

Re: [Solved] Save game blowing up with my custom dungeon

Post by Thorham »

minmay wrote:The reference would have to be serialized.
Seems simple enough.

1. Store ID of the object the reference points to.
2. Set a bit in a bit field (or something like that) that indicates the variable/table entry is a reference.
3. At load time, check bit in bit field. If it's a reference, get the ID and do a findEntity().

Of course, you'd have to make sure that all the objects are loaded before you set up the references.
User avatar
Lark
Posts: 178
Joined: Wed Sep 19, 2012 4:23 pm
Location: Springfield, MO USA

Re: [Solved] Save game blowing up with my custom dungeon

Post by Lark »

minmay wrote: As it happens, Lark didn't read this page, and posted multiple broken scripts to this forum.
Well yes, I posted that and other scripts before this page existed, just like everyone else who made the same mistake. Sorry I missed updating that one, but I posted other updates and even warned others of this problem (viewtopic.php?f=22&t=8129#p82285). :o Guess I should keep my new puzzle scripts to my self 'cause I'm too stupid to read. No need to throw me under the bus, minmay. -Lark
User avatar
Soaponarope
Posts: 180
Joined: Thu Oct 04, 2012 3:21 am

Re: [Solved] Save game blowing up with my custom dungeon

Post by Soaponarope »

I didn't mean anything negative with my post Lark, your one of the best scripters here and your scripts help me learn. My bad for not being aware of the issue until it happened to me.
MrChoke
Posts: 324
Joined: Sat Oct 25, 2014 7:20 pm

Re: [Solved] Save game blowing up with my custom dungeon

Post by MrChoke »

minmay wrote:"Tells you nothing"? It tells you EXACTLY what went wrong: you have a field that can't be serialized.
The stack trace gives nothing on the source of the bad variable. The message itself always talks about "cannot concatenate ID... etc", never giving the ID of the variable giving problems. You get nothing to help you find the source. I don't even think it says the word "serialized". So basically Minmay, I don't know what you are talking about when you say it tells you anything.
User avatar
Lark
Posts: 178
Joined: Wed Sep 19, 2012 4:23 pm
Location: Springfield, MO USA

Re: [Solved] Save game blowing up with my custom dungeon

Post by Lark »

Soaponarope wrote:I'm having this problem with my dungeon and I just found the cause. It was a nice script I found from Lark to fix the wall lanterns.
Sorry I caused you problems, Soaponarope. I didn't know about the issue until after I lots more information was discovered or posted. I warned others and corrected some past and subsequent posts, but missed this one. I owe you a pizza. :oops: Sorry! -Lark
User avatar
Lark
Posts: 178
Joined: Wed Sep 19, 2012 4:23 pm
Location: Springfield, MO USA

Re: [Solved] Save game blowing up with my custom dungeon

Post by Lark »

Soaponarope wrote:I didn't mean anything negative with my post Lark, your one of the best scripters here and your scripts help me learn. My bad for not being aware of the issue until it happened to me.
Hey! No offence taken! You were the innocent victim here. I owe you an apology (and a pizza). I wish Minmay would have contacted me about any errors found or even posted corrections to the original posts. We're all learning here and we all make mistakes. I'm fine to own up to mine and make corrections. I'm sorry I caused you such troubles over such a simple error on my part. Read the posts - others fell in the same trap and a lot of code has had to be changed. I posted an update at the original site, but can't test it until tonight. At first, none of us were doing much testing in a read dungeon and even then, not across saves, but we sure are now! So again, sorry for the troubles and the next pizza and a cold one are on me! -Lark
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: [Solved] Save game blowing up with my custom dungeon

Post by minmay »

MrChoke wrote:The stack trace gives nothing on the source of the bad variable. The message itself always talks about "cannot concatenate ID... etc", never giving the ID of the variable giving problems. You get nothing to help you find the source. I don't even think it says the word "serialized". So basically Minmay, I don't know what you are talking about when you say it tells you anything.
Really? All I ever saw was:
"cannot serialize variable of type X"
"cannot serialize table with metatable"
"cannot serialize function with upvalues"
etc..

Can you give me an example of a case where it gives "cannot concatenate..."?
Lark wrote:stuff
I was trying to warn people about other scripts rather than make a personal insult. Sorry if it came off otherwise. There much more problematic scripts posted here pretty much daily, so I probably shouldn't have singled you out.
However, that page definitely existed before Grimrock 2 was released.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Post Reply