However, when I start to use the same commands in the script. It never works.
Code: Select all
-- if not defines then
-- require "defines"
-- defines.train_state = defines.trainstate
-- end
--
MOD_NAME = "CreativeMode"
script.on_init(on_init)
script.on_load(on_load)
local function on_init()
init_players()
end
local function init_player(player)
player.print("The game has run for " .. math.floor(game.tick / 60) .. " seconds.")
global.gui[player.index] = global.gui[player.index] or util.table.deepcopy(defaultGuiSettings)
if global.unlockedByForce[player.force.name] then
GUI.init_gui(player)
end
end
local function init_players()
for _,player in pairs(game.players) do
init_player(player)
player.gui.top.add{type = "flow", name = "Example_Flow", direction = "horizontal"}
player.gui.top.Example_Flow.add{type = "label", caption = "Example Label"}
player.gui.top.Example_Flow.add{type = "button", caption = "Example Button"}
player.gui.top.Example_Flow.add{type = "checkbox", caption = "Example Checkbox", state = false}
end
end
local function on_load()
end
Edit: This is being done in the control.lua at the root of the mod.
SOLVED: So it seems
Code: Select all
script.on_event(defines.events.on_player_created, function(event)
At this point game and player should exist by then.