Crash Saving with items in alcoves

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
Darsithis
Posts: 51
Joined: Wed Jul 24, 2013 6:31 pm

Crash Saving with items in alcoves

Post 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
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Crash Saving with items in alcoves

Post 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.
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.
Darsithis
Posts: 51
Joined: Wed Jul 24, 2013 6:31 pm

Re: Crash Saving with items in alcoves

Post 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!
Darsithis
Posts: 51
Joined: Wed Jul 24, 2013 6:31 pm

Re: Crash Saving with items in alcoves

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