I'm pretty sure I know what your problem is, as I get the same error if I make a "repro case" here...
So, one of the biggest things you need to be really careful about in your scripts is making sure that you do not have any references to entities stored in variables that are not local. So, for instance the following script entity will cause a crash (when you try to save from an exported dungeon)...
Code: Select all
function a()
something = self.go;
end
function b()
print(something)
end
a()
b()
If you run the above code, you will notice that the script actually prints "table: XXXXXX" to the debug log. This is because the variable "something" is stored in the script scope, not the function scope (like you would expect if you program in most other languages) and so is also available to function b() later.
So, the problem here, is that the line "something = self.go" is actually making a variable in the script's global scope pointing to the game object of this script entity. This variable hangs around and is stored in the script entity. When the game comes to save this script entity, it is trying to save the variable "something" into the save file. However, the variable is a reference to a game object, which the save file doesn't know how to save. This causes the crash.
You can fix this in two ways.
1. In this case, you might want "something" to just be a temporary variable that is used in a(). For this, you should just type... "local something = self.go" instead. By putting the word "local" at the start of the line, you are saying "keep this variable in this function only, and then delete it when this function is done". This is the tidiest solution, as long as you don't need to keep the variable around for method b(), and means you won't have any problems trying to save the variable (it gets deleted at the end of the method call).
2. If you do need to use that variable across multiple methods, then my advice is to first define it at the top of the script (mainly for you to keep track for). However, you still run into the problem that you can't save a game entity. Instead, you will have to just keep the ID of the entity in a variable and use findEntity to retrieve it later. So, in this case, I would change the above to the following...
Code: Select all
someEntity = nil;
function a()
someEntity = self.go.id;
end
function b()
if (someEntity ~= nil) then
local e = findEntity(someEntity);
if e ~= nil then
print(e)
end
end
end
a()
b()
Hope this makes sense.
Unfortunately, going through your existing code and finding these errors can be a bit tiresome. Hope you track them down okay.