Page 1 of 1

0.12.11 help: attempt to index global 'game' (a nil value)

Posted: Sat Oct 17, 2015 6:38 am
by Gergith
Hello.

I keep searching but I just don't get this so far. I realize I need to read a LOT more and will do so for further mods I plan to create. It just appears this hasn't really been addressed in a place I can find ;-)

I realize that I can no longer call the game function, but I'm not sure how else to do this. I'm at the bottom of the learning curve currently it seems :p To be very frank; this is my first mod that I hacked together from two other mods. Bob's clock mod and some command line info from daniel34. Any help would be much appreciated! I know how to program in C++ among a few other languages but am VERY new to LUA and factorio modding. So far i don't fully understand the syntax, but I'll get there!

I'm getting the error: __coordinates__/control.lua:5: attempt to index global 'game' (a nil value)

for the following code:

Code: Select all

require "defines"

if not coordinates then coordinates = {} end

game.on_event(defines.events.on_tick, function(event)
    
		for i, player in ipairs(game.players) do
			if player.gui.top.coordinatesGUI == nil then player.gui.top.add{type="button", name="coordinatesGUI"} end
			player.gui.top.coordinatesGUI.caption=string.format("x=%f y=%f",game.player.character.position.x,game.player.character.position.y)
		end
end)

Re: 0.12.11 help: attempt to index global 'game' (a nil value)

Posted: Sat Oct 17, 2015 9:34 am
by prg
https://forums.factorio.com/forum/vie ... =3&t=17087
Warning: Most of the mods will be broken by this release, most of the problems can be solved by find and replace of "game.on_" to "script.on_" in the mod script files.
Lua API calls on_load, on_init, on_configuration_changed, on_event and generate_event_name have been moved to a new namespace called script (so from now use script.on_load(...)). This will break many mods! The callback registered in on_load function doesn't have access to the game API. This is to avoid common desyncs. The on_init and on_configuration_changed still retain the access to the game API.

Re: 0.12.11 help: attempt to index global 'game' (a nil value)

Posted: Sat Oct 17, 2015 11:31 pm
by Gergith
prg wrote:https://forums.factorio.com/forum/vie ... =3&t=17087
Warning: Most of the mods will be broken by this release, most of the problems can be solved by find and replace of "game.on_" to "script.on_" in the mod script files.
Lua API calls on_load, on_init, on_configuration_changed, on_event and generate_event_name have been moved to a new namespace called script (so from now use script.on_load(...)). This will break many mods! The callback registered in on_load function doesn't have access to the game API. This is to avoid common desyncs. The on_init and on_configuration_changed still retain the access to the game API.

Thank you so very much PRG!

Works like a charm. Some how I never actually found the snip-it about the find and replace of "game.on_" to "script.on_".

Thanks again for your help!