[0.18.8] game.print() adds extra spaces after "\n"

Bugs that are actually features.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

[0.18.8] game.print() adds extra spaces after "\n"

Post by eradicator »

What?

When using game.print (or player.print) to print a plain string that contains newlines ('\n') then four extra spaces are added after each newline.

Here's an example of string-with-newline vs for-looped-print:

Code: Select all

/c x = {'One','Two','Three','Four'} game.print(table.concat(x,'\n'))
/c x = {'One','Two','Three','Four'} for _,v in pairs(x) do game.print(v) end
extraindent.png
extraindent.png (332.56 KiB) Viewed 1641 times
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 4164
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [0.18.8] game.print() adds extra spaces after "\n"

Post by boskid »

From what i see, it is not a bug. Every console item goes through wrapping that changes message into multiple lines and every line after first is then indented with width equivalent of 4 spaces. newline simply forces console item to be split into multiple lines.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: [0.18.8] game.print() adds extra spaces after "\n"

Post by eradicator »

That is rather unfortunate. I guess i'll have to go ahead and write a function that splits strings with '\n' and then calls print multiple times to avoid the wrapping. ~.~

Thanks for having a look.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Rseding91
Factorio Staff
Factorio Staff
Posts: 16098
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.18.8] game.print() adds extra spaces after "\n"

Post by Rseding91 »

Or, just don't. Because then all of your messages will be inconsistent with how every other wrapped message works in the game.

When any message gets wrapped that's what happens to it in the output chat section. You can see it happen with the results of the /help command as well. Doing extra work to make your mod output *not* follow the standard method of line wrapping in chat output will just make your mod stick out as broken.
If you want to get ahold of me I'm almost always on Discord.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: [0.18.8] game.print() adds extra spaces after "\n"

Post by eradicator »

Rseding91 wrote: Fri Mar 06, 2020 3:40 pm Or, just don't. Because then all of your messages will be inconsistent with how every other wrapped message works in the game.

When any message gets wrapped that's what happens to it in the output chat section. You can see it happen with the results of the /help command as well. Doing extra work to make your mod output *not* follow the standard method of line wrapping in chat output will just make your mod stick out as broken.
Install /sudo. Type /sudo help create. Then we talk again. Oh, and btw tooltips have the opposite brokenness, they lack indentation. But with that kind of reaction i'm not even gonna bother to write an extra post for it. *sigh*
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Rseding91
Factorio Staff
Factorio Staff
Posts: 16098
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.18.8] game.print() adds extra spaces after "\n"

Post by Rseding91 »

eradicator wrote: Fri Mar 06, 2020 5:18 pm
Rseding91 wrote: Fri Mar 06, 2020 3:40 pm Or, just don't. Because then all of your messages will be inconsistent with how every other wrapped message works in the game.

When any message gets wrapped that's what happens to it in the output chat section. You can see it happen with the results of the /help command as well. Doing extra work to make your mod output *not* follow the standard method of line wrapping in chat output will just make your mod stick out as broken.
Install /sudo. Type /sudo help create. Then we talk again. Oh, and btw tooltips have the opposite brokenness, they lack indentation. But with that kind of reaction i'm not even gonna bother to write an extra post for it. *sigh*
The output of anything outside Factorio is irrelevant and I couldn't possibly care less how it works. Factorio chat output is what i'm talking about here.
If you want to get ahold of me I'm almost always on Discord.
Jap2.0
Smart Inserter
Smart Inserter
Posts: 2545
Joined: Tue Jun 20, 2017 12:02 am
Contact:

Re: [0.18.8] game.print() adds extra spaces after "\n"

Post by Jap2.0 »

Rseding91 wrote: Fri Mar 06, 2020 6:00 pm
eradicator wrote: Fri Mar 06, 2020 5:18 pm
Rseding91 wrote: Fri Mar 06, 2020 3:40 pm Or, just don't. Because then all of your messages will be inconsistent with how every other wrapped message works in the game.

When any message gets wrapped that's what happens to it in the output chat section. You can see it happen with the results of the /help command as well. Doing extra work to make your mod output *not* follow the standard method of line wrapping in chat output will just make your mod stick out as broken.
Install /sudo. Type /sudo help create. Then we talk again. Oh, and btw tooltips have the opposite brokenness, they lack indentation. But with that kind of reaction i'm not even gonna bother to write an extra post for it. *sigh*
The output of anything outside Factorio is irrelevant and I couldn't possibly care less how it works. Factorio chat output is what i'm talking about here.
I believe he's referring to https://mods.factorio.com/mod/eradicators-sudo.
There are 10 types of people: those who get this joke and those who don't.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: [0.18.8] game.print() adds extra spaces after "\n"

Post by eradicator »

Jap2.0 wrote: Sat Mar 07, 2020 2:11 am I believe he's referring to https://mods.factorio.com/mod/eradicators-sudo.
I am indeed. And the "let's treat automatic linebreaks the same as manual ones" is what's making the formatting difficult. But anyway the thread was moot by the time @boskid was so nice to confirm that it's on purpose. And i have no clue what @Rsedind even intended to achive by telling me i'm doing things wrong without even knowing what the output is.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Post Reply

Return to “Not a bug”