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

Place to get help with not working mods / modding interface.
Post Reply
User avatar
steinio
Smart Inserter
Smart Inserter
Posts: 2633
Joined: Sat Mar 12, 2016 4:19 pm
Contact:

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

Post 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 2780 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
Image

Transport Belt Repair Man

View unread Posts

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

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

Post 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.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

User avatar
steinio
Smart Inserter
Smart Inserter
Posts: 2633
Joined: Sat Mar 12, 2016 4:19 pm
Contact:

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

Post 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
Image

Transport Belt Repair Man

View unread Posts

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

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

Post 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.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
steinio
Smart Inserter
Smart Inserter
Posts: 2633
Joined: Sat Mar 12, 2016 4:19 pm
Contact:

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

Post 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
Image

Transport Belt Repair Man

View unread Posts

Rseding91
Factorio Staff
Factorio Staff
Posts: 13204
Joined: Wed Jun 11, 2014 5:23 am
Contact:

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

Post 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 :)
If you want to get ahold of me I'm almost always on Discord.

User avatar
steinio
Smart Inserter
Smart Inserter
Posts: 2633
Joined: Sat Mar 12, 2016 4:19 pm
Contact:

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

Post 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.
Image

Transport Belt Repair Man

View unread Posts

seronis
Fast Inserter
Fast Inserter
Posts: 225
Joined: Fri Mar 04, 2016 8:04 pm
Contact:

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

Post 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

Post Reply

Return to “Modding help”