[0.3.2] OnLoad triggered on save.

Bugs that we were not able to reproduce, and/or are waiting for more detailed info.
User avatar
rk84
Filter Inserter
Filter Inserter
Posts: 556
Joined: Wed Feb 13, 2013 9:15 am
Contact:

[0.3.2] OnLoad triggered on save.

Post 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?
Test mode
Searching Flashlight
[WIP]Fluid handling expansion
[WIP]PvP gamescript
[WIP]Rocket Express
Autofill: The torch has been pass to Nexela
kovarex
Factorio Staff
Factorio Staff
Posts: 8211
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: [0.3.2] OnLoad triggered on save.

Post 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.
User avatar
rk84
Filter Inserter
Filter Inserter
Posts: 556
Joined: Wed Feb 13, 2013 9:15 am
Contact:

Re: [0.3.2] OnLoad triggered on save.

Post 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. :?
Test mode
Searching Flashlight
[WIP]Fluid handling expansion
[WIP]PvP gamescript
[WIP]Rocket Express
Autofill: The torch has been pass to Nexela
kovarex
Factorio Staff
Factorio Staff
Posts: 8211
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: [0.3.2] OnLoad triggered on save.

Post by kovarex »

You most probably discovered some bug. (Thx for it ^^).
slpwnd
Factorio Staff
Factorio Staff
Posts: 1835
Joined: Sun Feb 03, 2013 2:51 pm
Contact:

Re: [0.3.2] OnLoad triggered on save.

Post 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?
User avatar
rk84
Filter Inserter
Filter Inserter
Posts: 556
Joined: Wed Feb 13, 2013 9:15 am
Contact:

Re: [0.3.2] OnLoad triggered on save.

Post 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.
Test mode
Searching Flashlight
[WIP]Fluid handling expansion
[WIP]PvP gamescript
[WIP]Rocket Express
Autofill: The torch has been pass to Nexela
Post Reply

Return to “Pending”