Page 1 of 1

Crash Saving with items in alcoves

Posted: Mon Jun 02, 2014 12:51 am
by Darsithis
The code below works great...but causes an exception that crashes Grimrock if you try to save the game with anything in any of the alcoves. Thoughts? Has anyone had this issue before?

Code: Select all

function CheckAlcovesFull()
	alcoveList = {"shieldAlcove1", "shieldAlcove2", "shieldAlcove3", "shieldAlcove4", "shieldAlcove5", "shieldAlcove6"}
	
	for index = 1, #alcoveList do
		foundAlcove = findEntity(alcoveList[index])
		
		for alcoveItem in foundAlcove:containedItems() do
			if alcoveItem.name == "shining_shield" then
				shieldCounter:increment()
			end
		end
	end
	
	if shieldCounter:getValue() == 6 then
		shieldsExitDoor:open()
	else
		shieldCounter:reset()
	end

end

Re: Crash Saving with items in alcoves

Posted: Mon Jun 02, 2014 3:20 am
by minmay
http://www.grimrock.net/modding/save-ga ... variables/

This line:

Code: Select all

foundAlcove = findEntity(alcoveList[index])
is storing an entity reference in a persistent variable, which cannot be serialized and will cause a crash if the player attempts to save.
You want to use the 'local' keyword:

Code: Select all

local foundAlcove = findEntity(alcoveList[index])
That way, the variable will go out of scope when the for loop exits, and it won't need to be saved.

Re: Crash Saving with items in alcoves

Posted: Mon Jun 02, 2014 4:46 am
by Darsithis
minmay wrote:http://www.grimrock.net/modding/save-ga ... variables/

This line:

Code: Select all

foundAlcove = findEntity(alcoveList[index])
is storing an entity reference in a persistent variable, which cannot be serialized and will cause a crash if the player attempts to save.
You want to use the 'local' keyword:

Code: Select all

local foundAlcove = findEntity(alcoveList[index])
That way, the variable will go out of scope when the for loop exits, and it won't need to be saved.
Oh thank you, you're a lifesaver!

Re: Crash Saving with items in alcoves

Posted: Wed Jun 04, 2014 1:32 am
by Darsithis
That didn't fix it. Even set local it still causes an exception when saving.

I'll just do away with the array and loop and check each alcove individually by name.