Page 1 of 1

Possible to print localised_strings to headless server console?

Posted: Thu Apr 06, 2023 6:19 pm
by credomane
I've been using the "print()" function to print to the server console (stdout) which works. Now I'm trying to print custom death messages and running into an issue.

Let's say I want to print "Credomane has died to a Small biter." when I die to a, well, small biter. So what I naively tried to do was

Code: Select all

script.on_event(defines.events.on_player_died, function(event)
	local p = game.players[event.player_index];
	local c = event.cause
	if not c then
		print("**" .. p.name .. "** died.");
	else
		print({"", "**" .. p.name .. "** died to a " , c.localised_name, "."});
	end
end)
Instead of the expected message I get "table" printed to stdout. Seems that the print() function doesn't handle localised_strings? I know game.print() does and so does every other method I know of but I need it in the headless console without printing it to players. The only method I know of for printing to stdout is "print()". "log()" from what read does handle localised_strings but it outputs to factoro-current.log and not stdout.

Re: Possible to print localised_strings to headless server console?

Posted: Thu Apr 06, 2023 6:23 pm
by credomane
....Of course. Every...single...time. I search and search and search. Come up empty handed. I post my question and immediately find the answer.
localised_print() allows printing LocalisedString to stdout without polluting the Factorio log file. This is primarily useful when communicating with external tools that launch Factorio as a child process.