game.print in on_init?
game.print in on_init?
I'm a bit confused as to why game.print doesn't work in on_init.
Checking active mods with game.active_mods works fine, but posting a message about found mods wont.
Checking active mods with game.active_mods works fine, but posting a message about found mods wont.
My Mods: mods.factorio.com
Re: game.print in on_init?
i think on_init() is run before any player is created.
Doing in on_init() should confirm it (or not)
Doing
Code: Select all
for i, p in pairs(game.players) log(i) end
Re: game.print in on_init?
Seems like players are not created in on_init.
Probably game.print can write to nil since it doesn't throw an error. I was kind of hoping it'd buffer messages and post them once players are created.
Probably game.print can write to nil since it doesn't throw an error. I was kind of hoping it'd buffer messages and post them once players are created.
My Mods: mods.factorio.com
Re: game.print in on_init?
There are no players in on_init in a new map. Game.print should work on an existing world that already has players during on_init because:Optera wrote:Seems like players are not created in on_init.
Game.print is probably doing something equivalent to thisProbably game.print can write to nil since it doesn't throw an error. I was kind of hoping it'd buffer messages and post them once players are created.
Code: Select all
for _, player in pairs(game.players) do
print message
end
Re: game.print in on_init?
Correct. It's a simple shortcut so you don't have to do the loop yourself. It's the same with http://lua-api.factorio.com/latest/LuaF ... orce.printNexela wrote:Game.print is probably doing something equivalent to this
So if there are no players the loop won't run. since no one is in the forest they don't hear the tree fallCode: Select all
for _, player in pairs(game.players) do print message end
If you want to get ahold of me I'm almost always on Discord.
Re: game.print in on_init?
Hm. In theory the way to implement such a print would be to look, if any player is connected to the game. If not it remembers the to printed string in a global variable and initialize some event handler that prints this in the moment when all players are (re)connected.
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...
Re: game.print in on_init?
Basically what we have to do right now is store the strings, trigger a run_once part of on_tick, print all strings.ssilk wrote:Hm. In theory the way to implement such a print would be to look, if any player is connected to the game. If not it remembers the to printed string in a global variable and initialize some event handler that prints this in the moment when all players are (re)connected.
With that effort we can just as well move most of on_init and on_load into that run_once.
There should be an event on_load/init_complete that runs once when the Bootstrap phase is complete.
Last edited by Optera on Sun Dec 04, 2016 11:12 am, edited 1 time in total.
My Mods: mods.factorio.com
Re: game.print in on_init?
It wouldn't be too hard to do:Optera wrote:Basically what we have to do right now is store the strings, trigger a run_once part of on_tick, print all strings.ssilk wrote:Hm. In theory the way to implement such a print would be to look, if any player is connected to the game. If not it remembers the to printed string in a global variable and initialize some event handler that prints this in the moment when all players are (re)connected.
With that effort we can just as well move most of on_init and on_load into that run_once.
Code: Select all
function on_init()
string = "This is what i want to print"
string = string.." - This is some more info and what not"
global.string = string
end
function on_player_created()
if global.string then
game.print(global.string)
global.string = nil
end
end
Re: game.print in on_init?
Is on_player_created always after on_load and on_init but before the first on_tick?
My Mods: mods.factorio.com
Re: game.print in on_init?
On player created is after both on_init and on_load (you shouldn't need to use on_load for anything simple like this)Optera wrote:Is on_player_created always after on_load and on_init but before the first on_tick?
Im not sure, but i think it is before the first tick, the first player is created at tick 0, such that no tick has happened,
But i might be wrong
Re: game.print in on_init?
Well it won't matter for my intent of simply informing players when RailTanker was found. Using on_player_created shaves one check off from on_tick so I'll use it to display the messages in console.Klonan wrote:On player created is after both on_init and on_load (you shouldn't need to use on_load for anything simple like this)Optera wrote:Is on_player_created always after on_load and on_init but before the first on_tick?
Im not sure, but i think it is before the first tick, the first player is created at tick 0, such that no tick has happened,
But i might be wrong
If on_player_created was guaranteed to always be called before a player experiences a tick I could also move the actual check for other mods there from on_init and on_configuration_Changed.
My Mods: mods.factorio.com
Re: game.print in on_init?
Some things Keep in mindOptera wrote: If on_player_created was guaranteed to always be called before a player experiences a tick I could also move the actual check for other mods there from on_init and on_configuration_Changed.
on_player_created is only run once for each player (when the player is created) so adding your mod to an existing world this wouldn't run.
on_configuration_changed is run anytime any mod is added, removed, or version num changes (including "base")
on_init is run ONCE per world when it is first created. I.E in a new MP world New players joining won't get this, (same with on_config_changed I believe)
Stdlib handles this by logging the tick. If game.tick is not available then tick is 0. then on any subsequent calls to the logger it flushes everything in the buffer if tick>last_tick.ssilk wrote:Hm. In theory the way to implement such a print would be to look, if any player is connected to the game. If not it remembers the to printed string in a global variable and initialize some event handler that prints this in the moment when all players are (re)connected.
A player that isn't created won't have a tickOptera wrote:on_player_created was guaranteed to always be called before a player experiences a tick
Re: game.print in on_init?
Nexela wrote:Some things Keep in mindOptera wrote: If on_player_created was guaranteed to always be called before a player experiences a tick I could also move the actual check for other mods there from on_init and on_configuration_Changed.
on_player_created is only run once for each player (when the player is created) so adding your mod to an existing world this wouldn't run.
on_configuration_changed is run anytime any mod is added, removed, or version num changes (including "base")
on_init is run ONCE per world when it is first created. I.E in a new MP world New players joining won't get this, (same with on_config_changed I believe)
Stdlib handles this by logging the tick. If game.tick is not available then tick is 0. then on any subsequent calls to the logger it flushes everything in the buffer if tick>last_tick.ssilk wrote:Hm. In theory the way to implement such a print would be to look, if any player is connected to the game. If not it remembers the to printed string in a global variable and initialize some event handler that prints this in the moment when all players are (re)connected.
A player that isn't created won't have a tickOptera wrote:on_player_created was guaranteed to always be called before a player experiences a tick
http://lua-api.factorio.com/latest/LuaB ... ap.on_init
http://lua-api.factorio.com/latest/Data-Lifecycle.html
If you want to get ahold of me I'm almost always on Discord.