Transport Tycoon Forums

The place to talk about Transport Tycoon
It is currently Tue Nov 13, 2018 3:44 am

All times are UTC




Post new topic  Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Tue Dec 20, 2011 11:28 pm 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 4538
Location: /home/sweden
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:
GSSign.BuildSign(some_tile, Text(GSText.STR_GOAL, company_id, goal_value));


english.txt:
Code:
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)


Top
   
PostPosted: Wed Dec 21, 2011 12:32 am 
Offline
Traffic Manager
Traffic Manager
User avatar

Joined: Tue Feb 01, 2011 12:41 pm
Posts: 226
Brilliant!

As a request/suggestion, is there a way to drop the GSText at the beginning of the text string? So:
Code:
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


Top
   
PostPosted: Wed Dec 21, 2011 12:44 am 
Offline
Tycoon
Tycoon

Joined: Thu Dec 20, 2007 12:49 pm
Posts: 3653
Write this anywhere before you use it like that:
Code:
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.


Top
   
PostPosted: Wed Dec 21, 2011 1:22 am 
Offline
Traffic Manager
Traffic Manager
User avatar

Joined: Tue Feb 01, 2011 12:41 pm
Posts: 226
Yexo wrote:
Write this anywhere before you use it like that:
Code:
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


Top
   
PostPosted: Wed Dec 21, 2011 12:08 pm 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 4538
Location: /home/sweden
MinchinWeb wrote:
Brilliant!

As a request/suggestion, is there a way to drop the GSText at the beginning of the text string? So:
Code:
Text(STR_GOAL, company_id, goal_value)


What is probably possible to do within the library is:
Code:
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)


Top
   
PostPosted: Wed Dec 21, 2011 1:03 pm 
Offline
OpenTTD Developer
OpenTTD Developer

Joined: Mon May 31, 2004 9:21 am
Posts: 1303
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.


Top
   
PostPosted: Wed Dec 21, 2011 2:56 pm 
Offline
Tycoon
Tycoon

Joined: Thu Dec 20, 2007 12:49 pm
Posts: 3653
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!


Top
   
PostPosted: Wed Dec 21, 2011 7:31 pm 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 4538
Location: /home/sweden
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:
Text <- GSText

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


Top
   
PostPosted: Wed Dec 21, 2011 7:38 pm 
Offline
OpenTTD Developer
OpenTTD Developer

Joined: Mon May 31, 2004 9:21 am
Posts: 1303
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.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000-2018 phpBB Limited

Copyright © Owen Rudge/The Transport Tycoon Forums 2001-2018.
Hosted by Zernebok Hosting.