Page 3 of 4

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

Posted: Fri Dec 19, 2014 6:39 pm
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

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

Posted: Fri Dec 19, 2014 9:32 pm
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.

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

Posted: Fri Dec 19, 2014 10:14 pm
by minmay
The reference would have to be serialized.

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

Posted: Sat Dec 20, 2014 12:15 am
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.

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

Posted: Sat Dec 20, 2014 12:46 am
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

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

Posted: Sat Dec 20, 2014 1:02 am
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.

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

Posted: Sat Dec 20, 2014 1:04 am
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.

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

Posted: Sat Dec 20, 2014 1:06 am
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

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

Posted: Sat Dec 20, 2014 1:17 am
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

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

Posted: Sat Dec 20, 2014 1:19 am
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.