[SOLVED]Need help starting up mod.

Place to get help with not working mods / modding interface.
demonkingj
Manual Inserter
Manual Inserter
Posts: 1
Joined: Sun Jul 03, 2016 8:11 am
Contact:

[SOLVED]Need help starting up mod.

Post by demonkingj »

I have checked the online tutorials. I have been able to do all of the commands in the console in the game.

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
Buttons never show up at all. It seems that game is always nil.


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)
works.

At this point game and player should exist by then.
Post Reply

Return to “Modding help”