Page 1 of 1
[Script bug] game.onload bug
Posted: Sun Dec 15, 2013 8:47 pm
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
Re: [Script bug] game.onload bug
Posted: Mon Dec 16, 2013 12:33 am
by rk84
Re: [Script bug] game.onload bug
Posted: Mon Dec 16, 2013 12:53 am
by Dysoch
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.
Re: [Script bug] game.onload bug
Posted: Mon Dec 16, 2013 7:34 am
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.