GS string problem
Moderator: OpenTTD Developers
GS string problem
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.
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.
- planetmaker
- OpenTTD Developer
- Posts: 9432
- Joined: 07 Nov 2007 22:44
- Location: Sol d
Re: GS string problem
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.
OpenTTD: manual | online content | translations | Wanted contributions and patches
#openttdcoop: blog | wiki | public server | DevZone | NewGRF web translator
DevZone - home of the free NewGRFs: OpenSFX | OpenMSX | OpenGFX | Swedish Rails | OpenGFX+ Trains|RV|Industries|Airports|Landscape | NML
Re: GS string problem
"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.
The scripts that Planetmaker mentioned implement this as a "cargo list" with one entry.
Re: GS string problem
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, 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}
Re: GS string problem
well, technically "{STRING}" should mean "{STRINGID}", since you can only pass previously defined STR_BLAH values from a language file.
Re: GS string problem
Of course not. Openttd uses {STRING} directly for char object.
GS probably does not.
GS probably does not.
Re: GS string problem
can you show me an actual point in the source code where that happens?
Re: GS string problem
Ok, it works differently than I thougt.
Perhaps you could tell me how I can get string to goal gui?
Perhaps you could tell me how I can get string to goal gui?
Re: GS string problem
Here is the relevant code of NoCarGoal that make use of {CARGO_LIST}.
english.txt:
companydata.nut:
As you see the parameter to first {CARGO_LIST} is this code where the variable contains a cargo id:
(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)
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} %)
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);
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)
Junctioneer (a traffic intersection simulator)
Re: GS string problem
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:"
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:"
Re: GS string problem
{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));
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
Re: GS string problem
Great, thank you frosch. Problem solved
Who is online
Users browsing this forum: No registered users and 11 guests