Page 1 of 1
GS string problem
Posted: 15 Sep 2012 23:02
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.
Re: GS string problem
Posted: 16 Sep 2012 06:16
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.
Re: GS string problem
Posted: 16 Sep 2012 08:45
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.
Re: GS string problem
Posted: 16 Sep 2012 10:23
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}
Re: GS string problem
Posted: 16 Sep 2012 10:39
by Eddi
well, technically "{STRING}" should mean "{STRINGID}", since you can only pass previously defined STR_BLAH values from a language file.
Re: GS string problem
Posted: 16 Sep 2012 18:55
by Honza_
Of course not. Openttd uses {STRING} directly for char object.
GS probably does not.
Re: GS string problem
Posted: 16 Sep 2012 19:19
by Eddi
can you show me an actual point in the source code where that happens?
Re: GS string problem
Posted: 16 Sep 2012 21:53
by Honza_
Ok, it works differently than I thougt.
Perhaps you could tell me how I can get string to goal gui?
Re: GS string problem
Posted: 17 Sep 2012 10:32
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)
Re: GS string problem
Posted: 17 Sep 2012 11:43
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:"
Re: GS string problem
Posted: 17 Sep 2012 17:35
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));
Re: GS string problem
Posted: 17 Sep 2012 18:29
by Honza_
Great, thank you frosch. Problem solved