GameScript {INDUSTRY}

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
hpfx
Engineer
Engineer
Posts: 55
Joined: 09 Nov 2013 00:19

GameScript {INDUSTRY}

Post by hpfx »

Hello,
I would like to create a colored sign with industry name, but only with industry type (just "Farm", not "London Farm")
I made my sign with

Code: Select all

GSSign.BuildSign(tile_index,GSText(GSText.STR_INDUSTRY,industry_id))
with english.txt :
STR_INDUSTRY :{LTBROWN}{INDUSTRY}

it's works OK, but with the town name,
is there a way to get the same without town name ? I tried {INDUSTRY_SHORT} and _TINY}, any idea ?
thank you.
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: GameScript {INDUSTRY}

Post by planetmaker »

AFAIK you need to query the industry type's name. Not the industry name.
http://nogo.openttd.org/api/trunk/class ... yType.html
hpfx
Engineer
Engineer
Posts: 55
Joined: 09 Nov 2013 00:19

Re: GameScript {INDUSTRY}

Post by hpfx »

ok,
do you mean I have to take GSIndustryType::GetName()
But this one returns char*, not a GSText,
that means I can't build my sign with ottd special string features (color...)
krinn
Transport Coordinator
Transport Coordinator
Posts: 342
Joined: 29 Dec 2010 19:36

Re: GameScript {INDUSTRY}

Post by krinn »

STR_INDUSTRY_COLOR_BLUE : {BLUE}{STRING}
STR_INDUSTRY_FARM : Farm
STR_INDUSTRY_BANK : Bank
STR_INDUSTRY_NOMATCH : Unknown

Like planetmaker said use the industry type name. And use the good STR_INDUSTRY_ for your output.
local z = GSText(GSText.STR_INDUSTRY_COLOR_BLUE);
local match = false;
if (GSIndustry.GetName = "farm name") { match = true; z.AddParam(GSText(GSText.STR_INDUSTRY_FARM)); }
if (GSIndustry.GetName = "bank name") { match = true; z.AddParam(GSText(GSText.STR_INDUSTRY_BANK)); }
if (!match) { z.AddParam(GSText(GSText.STR_INDUSTRY_NOMATCH); }


I didn't check the return value of the GetName function, but if you want an even more generic function you can lookup the GSText class to find if the return value from a function match an existing string in it: (i'm sure you want a sample ?)

Code: Select all

local cargolist = GSCargoList();
foreach (cargo, _ in cargolist)
{
local k = GSCargo.GetCargoLabel(cargo);
foreach (key, _ in GSText)
   {
   local output = null;
   local cargotext = null;
   if (key.find("STR_CARGOTYPE_"+k) != null)  { cargotext = GSText(GSText["STR_CARGOTYPE_"+k]); }
   if (cargotype == null)  { output = GSText(GSText.STR_CARGOTYPE_NOTFOUND; }
                            else  { output = GSText(GSText.STR_CARGOTYPE_FOUND, cargotext); }
   }
}
and an english.txt with
STR_CARGOTYPE_FOUND : {GREEN}{STRING}
STR_CARGOTYPE_NOTFOUND: {RED}Not found in english.txt
STR_CARGOTYPE_COAL : Coal cargo
hpfx
Engineer
Engineer
Posts: 55
Joined: 09 Nov 2013 00:19

Re: GameScript {INDUSTRY}

Post by hpfx »

krinn wrote:foreach (key, _ in GSText)
Ho !
I didn't knew I could iterate through GSText,
very clever.

Thank you.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 10 guests