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

Place to get help with not working mods / modding interface.
Post Reply
User avatar
Gergith
Burner Inserter
Burner Inserter
Posts: 19
Joined: Fri Jul 24, 2015 4:35 am
Contact:

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

Post 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)
Currently using: Latest Steam build
Plugins: Bob's Mods|DyTech|Yuoki Industries|5Dim's Mod|Mineable Rock|AutoTrash|Advanced Logistics System|Landfill|Long Reach|Upgrade Planner
For Testing: Test Mode

Plus my own: Coordinates mod

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

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

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

User avatar
Gergith
Burner Inserter
Burner Inserter
Posts: 19
Joined: Fri Jul 24, 2015 4:35 am
Contact:

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

Post 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!
Currently using: Latest Steam build
Plugins: Bob's Mods|DyTech|Yuoki Industries|5Dim's Mod|Mineable Rock|AutoTrash|Advanced Logistics System|Landfill|Long Reach|Upgrade Planner
For Testing: Test Mode

Plus my own: Coordinates mod

Post Reply

Return to “Modding help”