Page 1 of 1

[0.3.2] OnLoad triggered on save.

Posted: Wed Apr 03, 2013 8:42 am
by rk84
I got "game.player.print("text")" in game.onload -event and noticed it printed text in autosave and manual saving.
This is in my mod and the mod does not use game.onsave -event at all.

Edit:
-I added "game.player.print(eventname)" in all script events.
-I made a new game and save it.
Print outputs:
OnInit
OnSave
OnLoad

And when I load the save I see the above output. No additional prints.
Now I'm wondering where does that "OnLoad" output comes. Did "game.onload" trigger or was the "Onload" output saved during "game.onsave"?

Edit2:
Also tried this in console:

Code: Select all

game.onsave(function() game.player.print("OnSave -console") end)
game.onload(function() game.player.print("OnLoad -console") end)
Output on save:
OnSave -console
OnLoad -console
OnSave
OnLoad

After loading the save, output is what it was. so game.onload does not trigger on load at all?

Re: [0.3.2] OnLoad triggered on save.

Posted: Wed Apr 03, 2013 2:50 pm
by kovarex
When the new game is created from scenario this is the way it works:

Scenario blueprint is loaded (scenario blueprint is slightly different file type than common save, it contains information about all difficulties for example)
Script is created (oninit called)

Scenario blueprint is saved in the temp/currently-playing directory as save game
Script is saved there (onsave called).

After this, the game is loaded as regular save game and you can play it, so onload is called.

Re: [0.3.2] OnLoad triggered on save.

Posted: Wed Apr 03, 2013 3:46 pm
by rk84
hmm It doesn't seem very usefull for modding to onload and onsave to be called together when game is saved.

Now I got problem with game side events...
Some reason I got double function calls from one event. (In most event types except onpickedupitem)
Like if I mined something. onplayermineditem will trigger twice. It should not be double print mistake in my mod, because it prints out reference to different stack tables. Still I only receive only one stack in inventory. :?

Re: [0.3.2] OnLoad triggered on save.

Posted: Wed Apr 03, 2013 4:06 pm
by kovarex
You most probably discovered some bug. (Thx for it ^^).

Re: [0.3.2] OnLoad triggered on save.

Posted: Wed Jun 19, 2013 9:44 am
by slpwnd
The fact that onload is called on the save is not a bug. It could be called an obscure feature. The script should work in such a way that calling save - load doesn't change the inner data of the script. Or better it can change the data itself (destroy them and then rebuild them) but the result should be as if the save - load was never called.

You mentioned some strange behavior. Could you elaborate on that one?

Re: [0.3.2] OnLoad triggered on save.

Posted: Thu Jun 20, 2013 3:28 pm
by rk84
slpwnd wrote:The fact that onload is called on the save is not a bug. It could be called an obscure feature. The script should work in such a way that calling save - load doesn't change the inner data of the script. Or better it can change the data itself (destroy them and then rebuild them) but the result should be as if the save - load was never called.

You mentioned some strange behavior. Could you elaborate on that one?
Ok. I think this can be moved to "Not a bug"-section.
To prevent useless loading. I think, I can do somethink like this?

Code: Select all

game.onload(function()
	if onsave == nil then
		--load
	end
end)

game.onsave(function()
	onsave = true
end)
About double events. It might have been that onpreplayermineditem played trick on me. I cant remember for sure and dunno what point it was added in game. But currently (0.5.x) I have not noticed any oddness with onevents.