Newlines in material

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

Post Reply
Aphid
Traffic Manager
Traffic Manager
Posts: 168
Joined: 16 Dec 2011 17:08

Newlines in material

Post by Aphid »

It has come to my attention that a lot of the means script uses to present data to users does not support newlines. News messages and the town info window text both do not display default '\n' characters as newlines, but will instead display '?'.
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 991
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: Newlines in material

Post by frosch »

"?" is displayed for every invalid character which is filtered by the validator.

The control code for new line in strings/translations is "{}". See http://wiki.openttd.org/Format_of_langf ... slations_2
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
Aphid
Traffic Manager
Traffic Manager
Posts: 168
Joined: 16 Dec 2011 17:08

Re: Newlines in material

Post by Aphid »

Are you sure?

Please check the two attached files.
It seems that just a basic non-text object string does not properly communicate '{}' either.
Attachments
SWF News.jpg
SWF News.jpg (22.08 KiB) Viewed 1686 times
SladworthFalls.jpg
SladworthFalls.jpg (31.55 KiB) Viewed 1686 times
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Newlines in material

Post by Zuu »

Indeed, {} and other control strings only works when used in translations. Using {} in a literal string to produce a new line in a .nut file will not work.

However, even if your script is only available in English, using lang/english.txt, you will already prepare your script so that it is easy for a non-programmer to contribute a translation of your script.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Aphid
Traffic Manager
Traffic Manager
Posts: 168
Joined: 16 Dec 2011 17:08

Re: Newlines in material

Post by Aphid »

If only I could do that...

But you see, there is but a slight problem. OpenTTD has 32 cargoes.

This means the string in question has up to 36 lines, 32 with 3 elements in them. That means it has up to around 110 sub-elements.
That's more than 20, the maximum for a GSText object. Since GSTown's line only accepts a single object it cannot be cut into multiple pieces either.

Thus I cannot use the english.txt.

Which leaves us with a dilemma, basically. Various solutions to it would be fine:

1) Somehow remove or raise to absurd amounts all length limitations from the string generation. E.g. have proper recursion. **
2) Somehow properly display "\n". The log does it, so why wouldn't other constructs?
3) Somehow allow objects that present to the user a single string object to instead (also) be able to present a table, list, and/or array of string objects.*

* Obviously, signs already provide this functionality by building multiples of them. The same goes for the Goal interface. But the Town window and News messages are not so well-equipped to deal with it.
** Increase SCRIPT_TEXT_MAX_PARAMETERS = 20 to maybe 300?

Either (1), (2), or (3) would provide a fix.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 10 guests