[NoGo] Text - a library for easier usage of GSText

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
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

[NoGo] Text - a library for easier usage of GSText

Post by Zuu » 20 Dec 2011 23:28

This library simplifies the usage of GSText. With this library you do not need to store the instance of GSText in order to set parameters. Using variable argument count it calls GSText.AddParam internally.

Example:
Squirrel code:

Code: Select all

GSSign.BuildSign(some_tile, Text(GSText.STR_GOAL, company_id, goal_value));
english.txt:

Code: Select all

STR_GOAL    :{COMPANY} should build {NUM} connections
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

User avatar
MinchinWeb
Traffic Manager
Traffic Manager
Posts: 226
Joined: 01 Feb 2011 12:41
Contact:

Re: [NoGo] Text - a library for easier usage of GSText

Post by MinchinWeb » 21 Dec 2011 00:32

Brilliant!

As a request/suggestion, is there a way to drop the GSText at the beginning of the text string? So:

Code: Select all

Text(STR_GOAL, company_id, goal_value)
Alberta Town Names - 1500+ real names from 'Acme' to 'Zama City'
MinchinWeb's Random Town Name Generator - providing 2 million plus names...
WmDOT v13 - An AI that doubles as your highway department

Yexo
Tycoon
Tycoon
Posts: 3653
Joined: 20 Dec 2007 12:49

Re: [NoGo] Text - a library for easier usage of GSText

Post by Yexo » 21 Dec 2011 00:44

Write this anywhere before you use it like that:

Code: Select all

STR_GOAL <- GSText.STR_GOAL;
Strings have been put in the GSText class to prevent any possible clashes with existing names (unlikely as they are if your strings start with STR_, but that is not a requirement).

Idea: force STR_ as prefix for all strings and put them in the global namespace.

User avatar
MinchinWeb
Traffic Manager
Traffic Manager
Posts: 226
Joined: 01 Feb 2011 12:41
Contact:

Re: [NoGo] Text - a library for easier usage of GSText

Post by MinchinWeb » 21 Dec 2011 01:22

Yexo wrote:Write this anywhere before you use it like that:

Code: Select all

STR_GOAL <- GSText.STR_GOAL;
That would work, but it wouldn't scale well if you have hundreds of strings in your language file.
Yexo wrote:Idea: force STR_ as prefix for all strings and put them in the global namespace.
This could work well and would scale well. Alternatively, is there a way to make everything in the GSText scope within the global scope? point the GSText scope to the mainbody scope of your GameScript maybe?
Alberta Town Names - 1500+ real names from 'Acme' to 'Zama City'
MinchinWeb's Random Town Name Generator - providing 2 million plus names...
WmDOT v13 - An AI that doubles as your highway department

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [NoGo] Text - a library for easier usage of GSText

Post by Zuu » 21 Dec 2011 12:08

MinchinWeb wrote:Brilliant!

As a request/suggestion, is there a way to drop the GSText at the beginning of the text string? So:

Code: Select all

Text(STR_GOAL, company_id, goal_value)
What is probably possible to do within the library is:

Code: Select all

Text("STR_GOAL", company_id, goal_value)
Then, using rawget it can probably get the STR_GOAL member of GSText.


Though, if the STR_ prefix is enforced and the constants placed at global scope, I think that will provide an easier syntax.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1312
Joined: 31 May 2004 09:21

Re: [NoGo] Text - a library for easier usage of GSText

Post by TrueBrain » 21 Dec 2011 13:03

I think, but I am not sure, you can just list all entries in a class (which are tables). So you should be able to list all members of GSText, match it against STR_, and put it in the global scope :)

foreach (idx, val in GSText) {} .. :)
The only thing necessary for the triumph of evil is for good men to do nothing.

Yexo
Tycoon
Tycoon
Posts: 3653
Joined: 20 Dec 2007 12:49

Re: [NoGo] Text - a library for easier usage of GSText

Post by Yexo » 21 Dec 2011 14:56

If the variable arguments to the constructor were the only addition in your Text-library, it's obsolete since r23651 as GSText now has that feature too. Very nice suggestion!

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [NoGo] Text - a library for easier usage of GSText

Post by Zuu » 21 Dec 2011 19:31

Yexo wrote:If the variable arguments to the constructor were the only addition in your Text-library, it's obsolete since r23651 as GSText now has that feature too. Very nice suggestion!
Unless I misunderstood Truebrain yesterday, he told me yesterday that it is hard/impossible to implement variable argument count for constructors in the interface between C++ and Squirrel. That's why I did publish this library on bananas. But apparently you guys solved this hard/impossible task in less than 24 hours. :)

Thus, if anyone wants to write Text instead of GSText they can just do:

Code: Select all

Text <- GSText
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1312
Joined: 31 May 2004 09:21

Re: [NoGo] Text - a library for easier usage of GSText

Post by TrueBrain » 21 Dec 2011 19:38

You know what they say. "the impossible only takes a bit longer" ;)
The only thing necessary for the triumph of evil is for good men to do nothing.

Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 2 guests