[Script bug] game.onload bug

Bugs that are actually features.
User avatar
Dysoch
Filter Inserter
Filter Inserter
Posts: 445
Joined: Fri Oct 18, 2013 2:27 pm
Contact:

[Script bug] game.onload bug

Post by Dysoch »

when adding an event like this:

Code: Select all

game.onload(function()
game.player.print("This message is for testing")
end)
it runs as it should, when the game is loaded.

the only problem is, it also runs the event when auto-saving!
thus rendering the onload event useless
Creator of:
- DyTech
- DyWorld
- DyWorld-Dynamics
- DyWorld-Dynamics 2
Active since Factorio 0.6
User avatar
rk84
Filter Inserter
Filter Inserter
Posts: 556
Joined: Wed Feb 13, 2013 9:15 am
Contact:

Re: [Script bug] game.onload bug

Post by rk84 »

mayby you can try this.
[0.3.2] OnLoad triggered on save
Test mode
Searching Flashlight
[WIP]Fluid handling expansion
[WIP]PvP gamescript
[WIP]Rocket Express
Autofill: The torch has been pass to Nexela
User avatar
Dysoch
Filter Inserter
Filter Inserter
Posts: 445
Joined: Fri Oct 18, 2013 2:27 pm
Contact:

Re: [Script bug] game.onload bug

Post by Dysoch »

rk84 wrote:mayby you can try this.
[0.3.2] OnLoad triggered on save
Sure, its a nice workaround.

But i try to keep my codes as clean as possible.
If they fix it, ill add my print to onload.

But now im using ontick with a timelapse of 216.000 ticks (aka 1 hour) as a replacement.
Creator of:
- DyTech
- DyWorld
- DyWorld-Dynamics
- DyWorld-Dynamics 2
Active since Factorio 0.6
slpwnd
Factorio Staff
Factorio Staff
Posts: 1835
Joined: Sun Feb 03, 2013 2:51 pm
Contact:

Re: [Script bug] game.onload bug

Post by slpwnd »

As mentioned in the post linked by rk84 this is not a bug, but an obscure feature. For some very technical reasons saving the script state is a destructive operation, therefore there has to be onload called afterwards to get back into the previous state. The function is not useless - it is often used for some custom serialization code. However as you correctly mentioned it can't be used for any user interaction.

As a solution maybe we could add another "hook" (function) that would be called only when the game is actually loaded.
Post Reply

Return to “Not a bug”