Page 1 of 1

Print to game console during on_init?

Posted: Fri Feb 24, 2023 3:49 am
by FuryoftheStars
Is it possible to print a message out to the console in game during the on_init event?

game.print(message) doesn't actually seem to output anything during this event. I know the function I've assigned to it is firing because a log(message) in the same function does output to the log. It's just that sometimes it's easier to get needed debugging output from right within the game vs alt+tabbing -> reload file -> scroll scroll scroll (especially when trying to test compatibility with other mods that are outputting to the log as well).

Re: Print to game console during on_init?

Posted: Fri Feb 24, 2023 5:35 am
by lyvgbfh
FuryoftheStars wrote:
Fri Feb 24, 2023 3:49 am
Is it possible to print a message out to the console in game during the on_init event?

game.print(message) doesn't actually seem to output anything during this event. I know the function I've assigned to it is firing because a log(message) in the same function does output to the log. It's just that sometimes it's easier to get needed debugging output from right within the game vs alt+tabbing -> reload file -> scroll scroll scroll (especially when trying to test compatibility with other mods that are outputting to the log as well).
It won't solve your question, but I use logexpert (or `tail` on linux) to watch the game log if I'm debugging and don't have factorio launching with the dedicated console window in the background. I would recommend it.

Re: Print to game console during on_init?

Posted: Fri Feb 24, 2023 6:09 am
by Pi-C
FuryoftheStars wrote:
Fri Feb 24, 2023 3:49 am
Is it possible to print a message out to the console in game during the on_init event?

game.print(message) doesn't actually seem to output anything during this event.
I think it is possible if there are players in the game. This would be the case in single player mode when on_init is run because your mod has been added to a running game. It wouldn't work when you start a new game (there is no player yet that could see the message), and it shouldn't work in multiplayer mode (because on_init will run before on_player_joined_game).

Re: Print to game console during on_init?

Posted: Fri Feb 24, 2023 6:48 am
by FuryoftheStars
Crap, I was afraid that was what it was going to come around to. Alright, thanks.