player.character == nill because of sandbox intro
Posted: Sat Apr 03, 2021 3:55 pm
Hello,
i am trying to make my mod working on current factorio version, but it seams there is missing player.character because of sandbox intro (exploding ship).
In my control.lua i have:
which throws this error:
I can clearly see by printing "ok", player.character is present after intro no matter if i skip it or leave it to finish.
player.create_character() also doesn't work before intro finish.
So my question is: Is there some event on_character_creation?
I haven't found it.
I simply dont want to run my functions on every tick.
Thank you!
Michal.
i am trying to make my mod working on current factorio version, but it seams there is missing player.character because of sandbox intro (exploding ship).
In my control.lua i have:
Code: Select all
local function on_player_joined_game(event)
local player = game.players[event.player_index]
if player.character == nil then
game.print("player.character nil")
end
player.character.character_running_speed_modifier = -0.4
end
script.on_event(defines.events.on_player_joined_game, on_player_joined_game)
When i changed it to run on every tick:attempt to index field 'character' (a nil value)
Code: Select all
local function on_tick(event)
for i, player in pairs(game.players) do
local player = game.players[i]
if player.character == nil then return end
game.print("ok")
player.character.character_running_speed_modifier = -0.4
end
end
script.on_event(defines.events.on_tick, on_tick)
player.create_character() also doesn't work before intro finish.
So my question is: Is there some event on_character_creation?
I haven't found it.
I simply dont want to run my functions on every tick.
Thank you!
Michal.