GS string problem

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
Honza_
Engineer
Engineer
Posts: 126
Joined: 29 Aug 2010 10:29

GS string problem

Post by Honza_ »

hello,
I am playing with GS and I bump into a problem with string conversion.
I have this string template.

STR_TOWN_REQ_GUI :{YELLOW}{STRING} Storage: {COMMA}({NUM}%), Delivered/Required: {COMMA}/{COMMA}

The {STRING} does not work, actually, it shows no output, just an empty space. Is if functional in GS?

The code is this

GSText(GSText.STR_TOWN_REQ_GUI, GSCargo.GetCargoLabel(cargoid), storage, max_storage, delivered, required);

Even if I set the string parameter to "some text here", it doesnt work. I havent found no guide for GS so far about hadnling strings.
Only solution I can come up with is to make STR for every variable I want there.
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: GS string problem

Post by planetmaker »

I'm not sure what's wrong, but did you look ath NoCarGoal or SiliconValley's codes? IIRC they should implement something like this in their goal screens.
Eddi
Tycoon
Tycoon
Posts: 8289
Joined: 17 Jan 2007 00:14

Re: GS string problem

Post by Eddi »

"Cargo Label" is not the name of the cargo. It is the 4-Letter-Code that represents the (NewGRF) identity of the cargo, and this is not a string, but technically a 32bit number, so you cannot display it with a "{STRING}" code.

The scripts that Planetmaker mentioned implement this as a "cargo list" with one entry.
Honza_
Engineer
Engineer
Posts: 126
Joined: 29 Aug 2010 10:29

Re: GS string problem

Post by Honza_ »

Thanks. {CARGO_LIST} works very well.

Eddi, the GetCargoLabel function returns string (or char), so it should behave like string I guess. Anyway, with {STRING} I cannot even display things like
local string = "Coal"

So Iwonder if it works in GS, because I also wanted to display name of the goal type in gui, but I cannot get it there with the {STRING}
Eddi
Tycoon
Tycoon
Posts: 8289
Joined: 17 Jan 2007 00:14

Re: GS string problem

Post by Eddi »

well, technically "{STRING}" should mean "{STRINGID}", since you can only pass previously defined STR_BLAH values from a language file.
Honza_
Engineer
Engineer
Posts: 126
Joined: 29 Aug 2010 10:29

Re: GS string problem

Post by Honza_ »

Of course not. Openttd uses {STRING} directly for char object.
GS probably does not.
Eddi
Tycoon
Tycoon
Posts: 8289
Joined: 17 Jan 2007 00:14

Re: GS string problem

Post by Eddi »

can you show me an actual point in the source code where that happens?
Honza_
Engineer
Engineer
Posts: 126
Joined: 29 Aug 2010 10:29

Re: GS string problem

Post by Honza_ »

Ok, it works differently than I thougt.
Perhaps you could tell me how I can get string to goal gui?
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: GS string problem

Post by Zuu »

Here is the relevant code of NoCarGoal that make use of {CARGO_LIST}.

english.txt:

Code: Select all

STR_GOAL_PROGRESS_NEWS  :Goal progress{}{}{CARGO_LIST}: {CARGO_SHORT} transported ({NUM} %){}{CARGO_LIST}: {CARGO_SHORT} transported ({NUM} %){}{CARGO_LIST}: {CARGO_SHORT} transported ({NUM} %)
companydata.nut:

Code: Select all

	GSNews.Create(GSNews.NT_GENERAL, GSText(GSText.STR_GOAL_PROGRESS_NEWS, 
			1 << this._goal_ptr._cargo_list[0],
			this._goal_ptr._cargo_list[0],
			this._transported_list[0],
			percent[0],

			1 << this._goal_ptr._cargo_list[1],
			this._goal_ptr._cargo_list[1],
			this._transported_list[1],
			percent[1],

			1 << this._goal_ptr._cargo_list[2],
			this._goal_ptr._cargo_list[2],
			this._transported_list[2],
			percent[2]
		), this._company_id);
As you see the parameter to first {CARGO_LIST} is this code where the variable contains a cargo id:

Code: Select all

1 << this._goal_ptr._cargo_list[0]

(yes, this code block above could be shortened with a for-loop which have been done at other parts of the code, just not here yet)
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Honza_
Engineer
Engineer
Posts: 126
Joined: 29 Aug 2010 10:29

Re: GS string problem

Post by Honza_ »

Thanks, I already used that to display cargo names.
But lets say I want to add something like goal type names.
I will have
STR_CV :Company value
STR_AT :Annutal turnover
STR_GOAL : Goal of the game: {STRING}

How can I get it together?
GSText(GSText.STR_GOAL, GSText.STR_CV);
does not work. It displays only "Goal of the game:"
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 991
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: GS string problem

Post by frosch »

{STRING} means that the parameter will be another GSText value, which can have parameters itself:

Code: Select all

GSText(GSText.STR_GOAL, GSText(GSText.STR_CV)); 
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
Honza_
Engineer
Engineer
Posts: 126
Joined: 29 Aug 2010 10:29

Re: GS string problem

Post by Honza_ »

Great, thank you frosch. Problem solved
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 9 guests