The mod can be found here: https://mods.factorio.com/mod/ArcEnemySwitch
I'm not sure what I'm doing wrong but it appears to be in the control.lua file
The code for my control.lua file is
Code: Select all
script.on_init(function()
init_gui()
--game.player.gui.top.add{type="label", name="modinfo", caption="Arc's Switch Mod"}
-- game.player.gui.top.add{type="checkbox", name="enemyswitch", caption="Enemy Switch", state= "false", enabled="true"}
-- game.player.gui.top.enemyswitch.caption = "Enemy/Friendly Switch"
end)
script.on_load(function()
init_gui()
end)
function init_gui()
--for _, player in pairs(game.players) do
if not player.gui.top.enemyswitch then
game.player.gui.top.add{type="label", name="modinfo", caption="Arc's Switch Mod"}
game.player.gui.top.add{type="checkbox", name="enemyswitch", caption="Enemy Switch", state= "false", enabled="true"}
game.player.gui.top.enemyswitch.caption = "Enemy/Friendly Switch"
end
end
script.on_event({defines.events.on_gui_checked_state_changed},
function (e)
local switch_bool = game.player.gui.top.enemyswitch.state
if e.element == "enemyswitch" then
if switch_bool == true then
game.players[e.player_index].force = game.forces["enemy"]
end
if switch_bool == false then
game.players[e.player_index].force = game.forces["player"]
end
end
end)
Error while running on_load: __ArcEnemySwitch__/control.lua:15: attempt to index global 'player' (a nil value)
I'm not sure how to fix this. I'm new to Lua so I'm not the best at it. I know a lot of the commands and what not but I'm not solid on how they work together just yet so I apologize for that.