GSText : "too many parameters"

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
keoz
Transport Coordinator
Transport Coordinator
Posts: 321
Joined: 16 Jul 2009 10:04

GSText : "too many parameters"

Post by keoz »

Hi,

I have an issue when using GSText. I (try to) use it to set a (monthly renewed) text in the townboxes. The text in townboxes are correct for the first part, but the text is cut and at the end it complains about: "too many parameters". As there:
bug-gs.png
bug-gs.png (41.77 KiB) Viewed 3877 times
Now. I know that the GSText documentation indicates that 20 parameters at most can be given in the GSText() call and this could be the cause of the problem. But I have a doubt about that, for two reasons:
- it is unclear to me whether the max 20 parameters rule applies only to the parameters which are directly in the GSText() call, or also to the parameters "nested" in sub-strings, themselves called by GSText.
- another GS (RealGrowth) also uses a some nested string, which in total has 23 parameters, which leads me to think that this is not the problem.

Here is my the code:

The relevant function in strings.nut (the function GoalTown::TownBoxText is called from another file, using GSTown.SetText(this.id, this.TownBoxText))

Code: Select all

function GoalTown::TownBoxText() {
	local text_townbox_title = GSText(GSText.STR_TOWNBOX_TITLE);
	local text_townbox_cargocat = [];
	local text_townbox;
	switch (::CargoCatNum) {
		case(3):
			text_townbox_cargocat.append(GSText(GSText.STR_CARGOCAT_PAXMAIL));
			text_townbox_cargocat.append(GSText(GSText.STR_CARGOCAT_GGOODS));
			text_townbox_cargocat.append(GSText(GSText.STR_CARGOCAT_GIND));
			text_townbox = GSText(GSText.STR_TOWNBOX_3CAT, text_townbox_title);
			break;
		case(5):
			text_townbox_cargocat.append(GSText(GSText.STR_CARGOCAT_PAXMAIL));
			text_townbox_cargocat.append(GSText(GSText.STR_CARGOCAT_GFOOD));
			text_townbox_cargocat.append(GSText(GSText.STR_CARGOCAT_GGOODS));
			text_townbox_cargocat.append(GSText(GSText.STR_CARGOCAT_RAWIND));
			text_townbox_cargocat.append(GSText(GSText.STR_CARGOCAT_TRANIND));
			text_townbox = GSText(GSText.STR_TOWNBOX_5CAT, text_townbox_title);
			break;
	}

	for (local i = 0; i < ::CargoCatNum; i++) {
		text_townbox_cargocat[i].AddParam(this.TownGoalsCat[i]);
		text_townbox_cargocat[i].AddParam(this.TownSuppliedCat[i]);
		text_townbox_cargocat[i].AddParam(this.TownStockPiledCat[i]);
		text_townbox.AddParam(text_townbox_cargocat[i]);
	}		
return text_townbox;
}
Note that the problem only appears in switch's case(5), not in case(3).

here the related english.txt

Code: Select all

STR_CARGOCAT_PAXMAIL   :{}Passengers & Mail: {NUM}/{NUM}/{NUM}
STR_CARGOCAT_GFOOD     :{}General food: {NUM}/{NUM}/{NUM}
STR_CARGOCAT_GGOODS    :{}General goods: {NUM}/{NUM}/{NUM}
STR_CARGOCAT_GIND      :{}Industrial goods: {NUM}/{NUM}/{NUM}
STR_CARGOCAT_RAWIND    :{}Raw industrial goods: {NUM}/{NUM}/{NUM}
STR_CARGOCAT_TRANIND   :{}Tr. industrial goods: {NUM}/{NUM}/{NUM}
STR_TOWNBOX_TITLE      :Cargo information (Required/Supplied/Stockpil.)
STR_TOWNBOX_3CAT       :{STRING}{STRING3}{STRING3}{STRING3}
STR_TOWNBOX_5CAT       :{STRING}{STRING3}{STRING3}{STRING3}{STRING3}{STRING3}
Hints ?
Patch - Let's timetable depot waiting time with the Wait in depot patch.
GameScript - Searching a new way to make your cities growing ? Try the Renewed City Growth GameScript.
My screenshots thread.
krinn
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 29 Dec 2010 19:36

Re: GSText : "too many parameters"

Post by krinn »

Sorry Keoz

Code: Select all

STR_TOWNBOX_5CAT       :{STRING}{STRING3}{STRING3}{STRING3}{STRING3}{STRING3}
{STRING} = 1 param
{STRING3} = STRING + 3 parameters -> 4 parameters (the string that need the 3 params + the 3 params)

Now count : 1 + (5*4) = 21
User avatar
keoz
Transport Coordinator
Transport Coordinator
Posts: 321
Joined: 16 Jul 2009 10:04

Re: GSText : "too many parameters"

Post by keoz »

krinn wrote:Sorry Keoz

Code: Select all

STR_TOWNBOX_5CAT       :{STRING}{STRING3}{STRING3}{STRING3}{STRING3}{STRING3}
{STRING} = 1 param
{STRING3} = STRING + 3 parameters -> 4 parameters (the string that need the 3 params + the 3 params)

Now count : 1 + (5*4) = 21
Ok, so that confirms what I thought.

But in this case, I don't understand how it is possible that in another script, something like that works:

Code: Select all

STR_CONCAT_1_3_6_6_2         :{STRING1}{STRING3}{STRING6}{STRING6}{STRING2}
That amounts to 23 parameters and it *does* works (i tried it). It's in this script of lukasz1985.

The relevant code:

Code: Select all

		local text_city;
			
		local text_target_population;
		if(target_population.tointeger() > current_population) {
			text_target_population = GSText(GSText.STR_TARGET_POPULATION_HIGHER, target_population);	
		} else {
			text_target_population = GSText(GSText.STR_TARGET_POPULATION_LOWER, target_population);
		}
		
		local text_impact_history = GSText(GSText.STR_IMPACT_HISTORY, 
			pop_effect_this_month, 
			pop_effect_prev_month, 
			pop_effect_before_prev_month);
		
		
		local text_pass_mail_goods = GSText(GSText.STR_PASS_MAIL_GOODS
			passanger_transported, passanger_effect.tointeger(),
			mail_transported, mail_effect.tointeger(), 
			goods_transported, goods_effect.tointeger()
		);
		local text_food_frut_bdmt = GSText(GSText.STR_FOOD_FRUT_BDMT, 
			food_transported, food_effect.tointeger(),
			fruit_transported, fruit_effect.tointeger(),
			bdmt_transported,bdmt_effect.tointeger()
		);
		local text_petr = GSText(GSText.STR_PETR, 
			petrol_transported, petrol_effect.tointeger()
		);
		
		text_city = GSText(GSText.STR_CONCAT_1_3_6_6_2,
		 	text_target_population, 
		 	text_impact_history,
		 	text_pass_mail_goods,
		 	text_food_frut_bdmt,
		 	text_petr
	 	);
		SetText(text_city);
What am I missing ?
Patch - Let's timetable depot waiting time with the Wait in depot patch.
GameScript - Searching a new way to make your cities growing ? Try the Renewed City Growth GameScript.
My screenshots thread.
krinn
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 29 Dec 2010 19:36

Re: GSText : "too many parameters"

Post by krinn »

No idea, better wait Zuu answer.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: GSText : "too many parameters"

Post by Zuu »

keoz wrote:That amounts to 23 parameters and it *does* works (i tried it). It's in this script of lukasz1985.

The relevant code:

Code: Select all

		local text_city;
			
		local text_target_population;
		if(target_population.tointeger() > current_population) {
			text_target_population = GSText(GSText.STR_TARGET_POPULATION_HIGHER, target_population);	
		} else {
			text_target_population = GSText(GSText.STR_TARGET_POPULATION_LOWER, target_population);
		}
		
		local text_impact_history = GSText(GSText.STR_IMPACT_HISTORY, 
			pop_effect_this_month, 
			pop_effect_prev_month, 
			pop_effect_before_prev_month);
		
		
		local text_pass_mail_goods = GSText(GSText.STR_PASS_MAIL_GOODS
			passanger_transported, passanger_effect.tointeger(),
			mail_transported, mail_effect.tointeger(), 
			goods_transported, goods_effect.tointeger()
		);
		local text_food_frut_bdmt = GSText(GSText.STR_FOOD_FRUT_BDMT, 
			food_transported, food_effect.tointeger(),
			fruit_transported, fruit_effect.tointeger(),
			bdmt_transported,bdmt_effect.tointeger()
		);
		local text_petr = GSText(GSText.STR_PETR, 
			petrol_transported, petrol_effect.tointeger()
		);
		
		text_city = GSText(GSText.STR_CONCAT_1_3_6_6_2,
		 	text_target_population, 
		 	text_impact_history,
		 	text_pass_mail_goods,
		 	text_food_frut_bdmt,
		 	text_petr
	 	);
		SetText(text_city);
What am I missing ?
Where do you get 23 from? 1 + 3 + 6 + 6 + 2 = 20.

Now it was some time ago I looked on this, but as far as I remember, raising this limit is non-trivial. Some script authors have worked this around by adding up strings and number as a raw text string and sending that to OpenTTD. That is not very pretty as you lose the capability to get translated strings by sending the data as parameter. Another way is to stay below the limit and if you need to display more, put that in in a story book page, a monthly news message or even as signs next to the town.

It have been suggested to allow a Town window to refer to a story page (click to show page) or add something similar as story page elements to the town window to work around the 20 parameter limit. There is also a limit on how long a string can be. I'm not really against these ideas, I even got some other ideas on related things, I just haven't had time to work on it more than the time I have put into creating the story book.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
keoz
Transport Coordinator
Transport Coordinator
Posts: 321
Joined: 16 Jul 2009 10:04

Re: GSText : "too many parameters"

Post by keoz »

Zuu wrote:Where do you get 23 from? 1 + 3 + 6 + 6 + 2 = 20.
Actually, 1 + 3 + 6 + 6 + 2 = 18. :wink:

But those 18 parameters are nested in strings which are themselves parameters of the whole generated string. In the ending, you have a two level parameters stuff: 18 parameters embedded in 5 strings which are themselves called as parameters = 23 (cf. over STR_CONCAT_1_3_6_6_2 :{STRING1}{STRING3}{STRING6}{STRING6}{STRING2}).

And here is my point. You and krinn are counting in two different ways (considering the two levels or not). My question is to understand what is the right one :tongue:

The point here is that there are two possibilities:
- whether I count my parameters as you did on the last example, and in this case, I would only have 16 parameters: in this case, I shouldn't get any error message. Then, what is wrong in my code ?
- OR: we have to sum up both levels (strings + sub-strings): in this case, I have 21 parameters and my error makes sense, but the other script have 23 parameters and it's still working. The question is: why ?
Patch - Let's timetable depot waiting time with the Wait in depot patch.
GameScript - Searching a new way to make your cities growing ? Try the Renewed City Growth GameScript.
My screenshots thread.
fabca2
Transport Coordinator
Transport Coordinator
Posts: 312
Joined: 14 Apr 2004 15:18
Location: Fr

Re: GSText : "too many parameters"

Post by fabca2 »

keoz wrote: That amounts to 23 parameters and it *does* works (i tried it). It's in this script of lukasz1985.
I think the right count is 21, not 23.
and no, sorry, it *does not* works, didn't you notified the last line ?

Code: Select all

:Petrol:60:300
did you wonder from where this first ":" comes from ?

I made a script with 21 param, and I got same glitch on last line, I changed my script to have less parameters, the glitch disappear.

These unexpected 21 parameters makes a bug in openttd, this bug is harmless, but we can't know about future : it's out of spec, it may crash...
it looks to work, it does not mean it works.
User avatar
keoz
Transport Coordinator
Transport Coordinator
Posts: 321
Joined: 16 Jul 2009 10:04

Re: GSText : "too many parameters"

Post by keoz »

fabca2 wrote:
keoz wrote: That amounts to 23 parameters and it *does* works (i tried it). It's in this script of lukasz1985.
I think the right count is 21, not 23.
My code has 21, but the other script has 23.

Reminder of my original question: what is the right way to count parameters between those 2 methods:
1) Only to count low-level paremeters (= the parameters of the parameters).
2) To count each level's parameters.

My initial guess was that the right way is 2, but I have a doubt because, at least at first sight, this other script seem[s/ed] to work.

Now, let's go back to my test case of the other script (not mine): its high level concatenating string is:
STR_CONCAT_1_3_6_6_2 :{STRING1}{STRING3}{STRING6}{STRING6}{STRING2}

Now, depending whether the right way to count is 1) or 2), we have:
case 1: 1+3+6+6+2 = 18 parameters.
case 2: STR_CONCAT_1_3_6_6_2 is a a string which contains 5 paremeters. (cf. the source code pasted above) Those 5 paremeters contains, together, 1+3+6+6+2 paremeters (=18), which gives a total of 23.

So, it's not 20, it's not 21, it's either 18, either 23.

fabca2 wrote:I made a script with 21 param, and I got same glitch on last line, I changed my script to have less parameters, the glitch disappear.

These unexpected 21 parameters makes a bug in openttd, this bug is harmless, but we can't know about future : it's out of spec, it may crash...
it looks to work, it does not mean it works.
Let me make something clear. I'm not asking to you to explain me "How can I go around the specifications ?" And I agree on the fact that "it apparently works" does not mean "it works correctly". What I [was/am] asking, was : how does the specification must be understood.
Zuu wrote:It have been suggested to allow a Town window to refer to a story page (click to show page) or add something similar as story page elements to the town window to work around the 20 parameter limit. There is also a limit on how long a string can be. I'm not really against these ideas, I even got some other ideas on related things, I just haven't had time to work on it more than the time I have put into creating the story book.
I don't think that the problem is the implementation of GSText and its 20 parameter limit, but the limit of GSTown.GetText(), who only accepts one GSText parameter. I'm maybee wrong, but wouldn't raising this limit be easier and more consistent ?
Patch - Let's timetable depot waiting time with the Wait in depot patch.
GameScript - Searching a new way to make your cities growing ? Try the Renewed City Growth GameScript.
My screenshots thread.
krinn
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 29 Dec 2010 19:36

Re: GSText : "too many parameters"

Post by krinn »

http://wiki.openttd.org/Strings#nested_resolution
This is doc i have use myself to understand {STRINGx} func.

And as town have a limit of place, script maker should really just put vitals info in it, and use some other way to display extra info.
the num/num/num to show given/need/stockpile info can be easy shorten to need/stockpile as nobody really cares how much you gave to a town as long as you see stockpile and how much to give.
Note that it can even more be compress to :
"Need : value" and swapping that with "Stockpile : value" when need is at 0 and everything goes in stock.

That's just a way to do it, but it tooked me 2s to reduce a 4 params string into a 2 params one.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: GSText : "too many parameters"

Post by Zuu »

keoz wrote:
Zuu wrote:It have been suggested to allow a Town window to refer to a story page (click to show page) or add something similar as story page elements to the town window to work around the 20 parameter limit. There is also a limit on how long a string can be. I'm not really against these ideas, I even got some other ideas on related things, I just haven't had time to work on it more than the time I have put into creating the story book.
I don't think that the problem is the implementation of GSText and its 20 parameter limit, but the limit of GSTown.GetText(), who only accepts one GSText parameter. I'm maybee wrong, but wouldn't raising this limit be easier and more consistent ?
I think you misunderstand me. We both talk about allowing multiple GSText to be used to compose a page of text. Neither I or you talk about extending GSText to accept more than 20 parameters. One solution I talk about is to link to a story page (click to show), another is that the page elements are displayed in the town window. A page element is basically a GSText, but can also be a reference to a map location (clicking it moves viewport there) or a goal. (see API)

The probably easiest way to get there is to implement this by adding a field to the story book page data structure telling if the page is related to a town. If so, don't display it in the book window, but instead in the town window. This needs to generalize some code in the story book window so it can be used from another window too.


Of course you could also extend the town to have a fixed set of maximum 5 GSText, but I think it is more flexible to use something like a story page that can have any number of elements. If the story book is used, you get the non-text elements implemented already for free.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 988
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: GSText : "too many parameters"

Post by frosch »

Just to confirm: keoz is counting correctly. STRINGn needs (n+1) parameters.
About the other script with the 23 parameters: It does not work. The script even throws errors about unknown string codes like "STRING14" and such, so basically it does not work in many places.

Technically the "(too many parameters)" is not supposed to appear in game at all. The API is supposed to error on it earlier, but the API was miscounting as well :p I've fixed that locally in addition to some improved error messages in the script log, but it is not quite finished yet.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
User avatar
keoz
Transport Coordinator
Transport Coordinator
Posts: 321
Joined: 16 Jul 2009 10:04

Re: GSText : "too many parameters"

Post by keoz »

Zuu wrote:I think you misunderstand me. We both talk about allowing multiple GSText to be used to compose a page of text. [...]
I perfectly understood you and I perfectly know that you weren't speaking about the 20 parameters in the paragraph I quoted. ;)

This part of my message was referring to another part of your message (there were you speak about "raising this limit is non-trivial", in the previous paragraph, but maybee I indeed dind't correcly understood this part of your message). But: sorry for unclear quoting. A bad habit of mine. Looks like in this topic I'm particularly unable to make myself clear.
frosch wrote:About the other script with the 23 parameters: It does not work. The script even throws errors about unknown string codes like "STRING14" and such, so basically it does not work in many places.
Indeed. I also saw the debug error messages (at least, when using -d script=5) about that "STRING14" code. Which is normal because we can't go beyond STRING7, if I understand correctly this. There is the same error message about STRING8. But IIRC what I've seen, those STRING8 and STRING14 stuff isn't even in the "active code" (by what I mean, they aren't actually used in any GSText() call). In the same time, the 23 parameter call doesn't gives any error message. But I might be wrong, I don't perfecly remember what I've seen when trying.

In any case, it doesn't matter. Once more, I weren't speaking about this other code as an example of what I would like be able to do. I were speaking about this code because it raised a doubt in me about the right way to understand specification.

And I finally have a clear answer:
frosch wrote:STRINGn needs (n+1) parameters.
So, thank you frosch. And thank you to everybody else answering, even if I wasn't that clear here.
Patch - Let's timetable depot waiting time with the Wait in depot patch.
GameScript - Searching a new way to make your cities growing ? Try the Renewed City Growth GameScript.
My screenshots thread.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 7 guests