I am trying to get a mod (https://mods.factorio.com/mods/kij336/autorun) working with my save.
The mod works on a new single player save but with a save that has had multiple users playing it throws an error:
Code: Select all
Error while running event on_tick (ID 0)
User isn't connected; can't read character
stack traceback:
__autorun__/control.lua:59: in function <__autorun__/control.lua:54>
I had a look at the source around line 59 and it seems to be referencing b.character (b being a local variable referencing game.players)
.
Here is a snippet of the source:
Code: Select all
--autorun
function autorun(a)
local b=game.players[a]
b.clean_cursor()
b.cursor_stack.set_stack({name="autorun",count=1})
b.character_build_distance_bonus=b.character_build_distance_bonus+200
b.build_from_cursor()
b.cursor_stack.clear()
b.character_build_distance_bonus=b.character_build_distance_bonus-200
end
function stoprun(a)
global.autorun.target[a]=false
global.autorun.auto[a]=false
end
script.on_event(defines.events.on_tick, function(event)
if global.autorun==nil then global.autorun={} end
if global.autorun.target==nil then global.autorun.target={} end
if global.autorun.auto==nil then global.autorun.auto={} end
for a,b in pairs(game.players) do
if b.character and global.autorun.auto[a] then
autorun(a)
end
if b.character and global.autorun.target[a] then
local direction=rotation(b.character,global.autorun.target[a])
b.walking_state = {walking = true, direction = direction}
if distance(b.position,global.autorun.target[a])<=0.2 or b.mining_state.mining then
global.autorun.target[a]=false
end
end
end
end)
Code: Select all
--press key
script.on_event("move", function(event)
stoprun(event.player_index)
autorun(event.player_index)
end)
script.on_event("autorun", function(event)
if global.autorun.auto[event.player_index] then global.autorun.auto[event.player_index]=false
else global.autorun.auto[event.player_index]=true end
end)
Any help appreciated.
EDIT: I ran
Code: Select all
/c game.player.print(game.player.index)