Common Serialization (Saving) Pitfalls

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!
Azel
Posts: 808
Joined: Thu Nov 06, 2014 10:40 pm

Re: Common Serialization (Saving) Pitfalls

Post by Azel » Sat Oct 03, 2015 7:21 am

Drakkan wrote:Hi guys. when trying to load the game from certain point (unfortunately I didnt noticed where it started went wrong) I get:

=== Software Failure ===

[string "Component.lua"]:0: invalid trigger action
stack traceback:
[C]: in function 'assert'
[string "Component.lua"]: in function 'addConnector'
[string "GameObject.lua"]: in function 'loadState'
[string "Map.lua"]: in function 'loadState'
[string "GameMode.lua"]: in function 'loadGame'
[string "GameMode.lua"]: in function 'update'
[string "Grimrock.lua"]: in function 'display'
[string "Grimrock.lua"]: in main chunk

any clues from a first look ?
Hey so today I got this error while testing the final version of my Mod. It was an easy thing to fix, but figured I would post the solution here in case anyone else encounters this issue.

The scenario:

1) The player traveled to a new location and stepped on a trigger
2) The trigger had a connector to a Script Entity that no longer existed
3) An on-screen error message appeared in the game, "warning! invalid connector action: script_entity_76.ConfirmMechAge"
4) Any time the player saves the game after this message occurs, the game will crash during the next attempt to load the game

How I caused this problem in the first place:

1) I originally had a script_entity_76 and it did have a method called, "ConfirmMechAge"
2) I then tied a floor_trigger to this Method.
3) Later (weeks later), I was making a change and decided to delete script_entity_76 and start something new
4) I thought I had removed all connectors to this Script, but I was wrong
5) I assumed that while playing the game, I would get a warning that a trigger was still connected to a non-existent entity (I was wrong)
6) During my Editor Testing, I never actually stepped on all my floor triggers, so I never encountered this error
7) During a full exported dungeon play-test, I caught this error

The lesson?

1) Be sure to document all dependencies in the game (Google, "Regression Testing")
2) Always fully play-test the exported version of your Dungeon before releasing it to the public

Fin :mrgreen:

User avatar
FeMaiden
Posts: 290
Joined: Wed Jan 16, 2013 8:16 am

Re: Common Serialization (Saving) Pitfalls

Post by FeMaiden » Mon Nov 09, 2015 12:46 pm

not sure this helps or not...but if you ever have a situation where you have like 100 floor triggers in your mod and can't figure out which one is causing the problem, you can hit ctrl-f or whatever hotkey you may have bound in your preferences to look at a list of all the entities you placed.
I mention this because I only just discovered it today...after almost a month of this

minmay
Posts: 2657
Joined: Mon Sep 23, 2013 2:24 am

Re: Common Serialization (Saving) Pitfalls

Post by minmay » Mon Nov 09, 2015 1:01 pm

Here's a script to detect invalid connector targets/actions in your dungeon.

Code: Select all

function connectorCheck()
	for l=1,Dungeon.getMaxLevels() do
		for e in Dungeon.getMap(l):allEntities() do
			for _,c in e:componentIterator() do
				if c.getConnectorCount then
					for i=1,c:getConnectorCount() do
						local event,target,action = c:getConnector(i)
						local tEntity = findEntity(target)
						if not tEntity then
							print("Nonexistent connector target: "..target.." (from "..e.id..")")
						else
							if not
							((tEntity.controller and tEntity.controller[action])
							or (tEntity.script and tEntity.script[action])) then
								print("Nonexistent connector action: "..action.." (from "..e.id.." to "..target..")")
							end
						end
					end
				end
			end
		end
	end
end
edit: note, this won't detect cases where:
- you have a ScriptComponent named "script" that has the action, but it's missing a ScriptController to go with it
- you have components named "controller" or "script" that aren't actually (Script)ControllerComponents or ScriptComponents
- a connector specifies an invalid event
I didn't bother including these because you would pretty much have to introduce them on purpose.
Last edited by minmay on Tue Nov 10, 2015 4:31 am, edited 1 time in total.
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
FeMaiden
Posts: 290
Joined: Wed Jan 16, 2013 8:16 am

Re: Common Serialization (Saving) Pitfalls

Post by FeMaiden » Mon Nov 09, 2015 11:33 pm

ha...whenever I think I've got this stuff figured out, someone comes in with a script proving just how little I really know.

User avatar
Isaac
Posts: 2957
Joined: Fri Mar 02, 2012 10:02 pm

Re: Common Serialization (Saving) Pitfalls

Post by Isaac » Tue Nov 10, 2015 2:32 am

That's a nice script [reading through it].

User avatar
Lord_Foul
Posts: 49
Joined: Wed Dec 09, 2015 6:05 am

Re: Common Serialization (Saving) Pitfalls

Post by Lord_Foul » Thu Mar 03, 2016 11:15 pm

holy fark
awesome thread!

User avatar
akroma222
Posts: 1024
Joined: Thu Oct 04, 2012 10:08 am

Re: Common Serialization (Saving) Pitfalls

Post by akroma222 » Wed Mar 23, 2016 3:17 pm

FeMaiden wrote:ha...whenever I think I've got this stuff figured out, someone comes in with a script proving just how little I really know.
Totally :lol:
Thanks minmay, that code is super useful!

vieuxchat
Posts: 48
Joined: Wed Mar 02, 2016 3:14 pm

Re: Common Serialization (Saving) Pitfalls

Post by vieuxchat » Sun Mar 27, 2016 11:36 pm

Oh my. I just understood the minimalSaveState problem...
I've carefully placed some objects just to discover that they are like reseted on load.
Is there a way to tell the game that those particuliar objects should be totally saved ? (I mean apart creating copy object definition with minimalSaveState = false)
I now understand why we can't offset the models directly in the editor -___-

minmay
Posts: 2657
Joined: Mon Sep 23, 2013 2:24 am

Re: Common Serialization (Saving) Pitfalls

Post by minmay » Mon Mar 28, 2016 12:22 am

vieuxchat wrote:Is there a way to tell the game that those particuliar objects should be totally saved ? (I mean apart creating copy object definition with minimalSaveState = false)
No.
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.

vieuxchat
Posts: 48
Joined: Wed Mar 02, 2016 3:14 pm

Re: Common Serialization (Saving) Pitfalls

Post by vieuxchat » Mon Mar 28, 2016 9:14 am

So sad.
Thank you anyway.

I hope the devs will add such a "check" in the editor of their future titles. It adds a lot to the mood to be able to place objects at exact location.
A must would be to be able to offset the models with the mouse (so we can visually place them) instead of groping with +dx +dy +dz.

Post Reply