Page 1 of 1

on_load: index global 'game' (a nil value)

Posted: Sat Apr 23, 2016 10:49 am
by steinio
Hello,

sorry but i'm standing on the hose like we germans say.

I have the following code in my on_load block:

Code: Select all

function _init()
	interval = (Config.TickCheck > 4) and Config.TickCheck or 5
end

--Register a callback to be run on module init.
script.on_init( 
	function()
		_init()
	end
)

--Register a function to be run on module load.
script.on_load(
	function()
		_init()
		game.remove_path(Config.BaseDir)
		--html.create()
	end
)
But on game load following error appears:
on_load.png
on_load.png (121.18 KiB) Viewed 3328 times
I thought the game class is already initated in on_load, but the error message tells different.

The strange thing is, all works fine until yesterday afternoon :).

Greetings steinio

Re: on_load: index global 'game' (a nil value)

Posted: Sat Apr 23, 2016 11:04 am
by prg
steinio wrote:I thought the game class is already initated in on_load, but the error message tells different.
The error message is correct: game does not exist yet in on_load.
steinio wrote:The strange thing is, all works fine until yesterday afternoon :).
Did you update from some really old version since then? game used to exist in on_load previously, before script was introduced in 0.12.11.

Re: on_load: index global 'game' (a nil value)

Posted: Sat Apr 23, 2016 11:14 am
by steinio
Well so i must thing about an other strategy.

My intention is, to create a file during load and forget.
Is global avaiable in 'on_load'?

No, all code is under 12.30.
Could be that i moved some code from on_tick to on-load.

A bit off-topic, but is the constant '__Dashboard__' available for processing? Like with entities '.version' or '.author'?

Thanks for answering.

Greetings steinio

Re: on_load: index global 'game' (a nil value)

Posted: Sat Apr 23, 2016 5:38 pm
by bobingabout
Yeah, on_load does not contain game on purpose. on_tick does though, so moving code from on_tick to on_load that contains game. would cause issues.
it was removed to force people to stop using their multiplayer-breaking scripts, a by-produce of game. being the method of calling a script instead of the newly introduced script., I don't know exact details though. onsave was removed completely.

In theory though... why do you need to create anything on load? everything that should matter should still exist from before you saved the game to load it, therefore, on_load shouldn't need to do much, so recreating a table? well, the table should still exists from before you saved the game, at least if the table was stored in global, global is saved, I'm not sure if other variables are or not.

And yes, Global is availble on_load.

Re: on_load: index global 'game' (a nil value)

Posted: Sat Apr 23, 2016 6:29 pm
by steinio
I found a way, in that i store a global variable with false and set it to true after the first tick of the game, where the file is created.

I create a html file for viewing game data.
See viewtopic.php?f=97&t=23962

Greetings steinio

Re: on_load: index global 'game' (a nil value)

Posted: Sat Apr 23, 2016 6:34 pm
by Rseding91
steinio wrote:I found a way, in that i store a global variable with false and set it to true after the first tick of the game, where the file is created.

I create a html file for viewing game data.
See viewtopic.php?f=97&t=23962

Greetings steinio
And now your mod isn't MP compatible and will break replays :)

Re: on_load: index global 'game' (a nil value)

Posted: Sat Apr 23, 2016 8:40 pm
by steinio
Why do you say this?
I did nothing to you :)

Ok i try something with migration script.
But with that i need to change the version number with every change in the html file.

Re: on_load: index global 'game' (a nil value)

Posted: Sat Apr 23, 2016 10:01 pm
by seronis
steinio wrote: But with that i need to change the version number with every change in the html file.
Obviously? When the mod changes the version number should change. Its why version numbers use the format major.minor.tweak. Just up the tweak digit by one