Page 1 of 1
[NoGo] Text - a library for easier usage of GSText
Posted: 20 Dec 2011 23:28
by Zuu
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
Re: [NoGo] Text - a library for easier usage of GSText
Posted: 21 Dec 2011 00:32
by MinchinWeb
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)
Re: [NoGo] Text - a library for easier usage of GSText
Posted: 21 Dec 2011 00:44
by Yexo
Write this anywhere before you use it like that:
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.
Re: [NoGo] Text - a library for easier usage of GSText
Posted: 21 Dec 2011 01:22
by MinchinWeb
Yexo wrote:Write this anywhere before you use it like that:
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?
Re: [NoGo] Text - a library for easier usage of GSText
Posted: 21 Dec 2011 12:08
by Zuu
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.
Re: [NoGo] Text - a library for easier usage of GSText
Posted: 21 Dec 2011 13:03
by TrueBrain
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) {} ..

Re: [NoGo] Text - a library for easier usage of GSText
Posted: 21 Dec 2011 14:56
by Yexo
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!
Re: [NoGo] Text - a library for easier usage of GSText
Posted: 21 Dec 2011 19:31
by Zuu
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:
Re: [NoGo] Text - a library for easier usage of GSText
Posted: 21 Dec 2011 19:38
by TrueBrain
You know what they say. "the impossible only takes a bit longer"
