get signlist with GSSignList on a gamescript ?

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
hpfx
Engineer
Engineer
Posts: 53
Joined: 09 Nov 2013 00:19

get signlist with GSSignList on a gamescript ?

Post by hpfx »

Hello,

I need support,
I am trying to fetch list of sign but it looks empty...
here is my code,

Code: Select all

local signs = GSSignList();
foreach( index, signid in signs)
{
	GSLog.Info("found a sign, "+index );
	if(GSSign.IsValidSign(signid))
	{
		local txt = GSSign.GetName(signid);
		GSLog.Info("text : " + txt);
	}
}
I set few sign on map, but we never enter the foreach ?... nothing appears on gamescript log.
any idea ?
thank you for your help.
User avatar
jfs
Tycoon
Tycoon
Posts: 1828
Joined: 08 Jan 2003 23:09
Location: Denmark

Re: get signlist with GSSignList on a gamescript ?

Post by jfs »

The GSSignList class is described like this:
Create a list of signs your company has created.
The "your company" part here is important: Usually the game script works as "no company" (that is, "the world" or "deity"), and thus it would not find any signs owned by companies.

You need to use GSCompanyMode to switch to operate as one of the companies in the game to be able to get a list of the signs that company has created. If you want all signs from all companies, you will need to switch to each of the companies in turn to list for them.
hpfx
Engineer
Engineer
Posts: 53
Joined: 09 Nov 2013 00:19

Re: get signlist with GSSignList on a gamescript ?

Post by hpfx »

jfs wrote: 10 Jan 2025 09:13 You need to use GSCompanyMode to switch to operate as one of the companies in the game to be able to get a list of the signs that company has created. If you want all signs from all companies, you will need to switch to each of the companies in turn to list for them.
Thank you, that's what I needed !

For one who need, here an example:

Code: Select all

    for(local ci=0;ci<15;ci++)
    {
        if(GSCompany.ResolveCompanyID(ci)!=GSCompany.COMPANY_INVALID)
        local cm = GSCompanyMode(ci)
        local signs = GSSignList();
        foreach( signid, x  in signs)
        {
            if(GSSign.IsValidSign(signid))
            {
                local txt = GSSign.GetName(signid);
                GSLog.Info("text : " + txt);
                if(txt.find("GS:") == 0)
                {
                    action=txt.slice(3);
                    // do somethng...
                }

            }
        }
        //back to deity mode
    }
from what I understood, the gamescript acts as company "ci" when the GSCompanyMode instance is live,
hence I created a local instance ("local cm"), that is destroyed at the end of the "for" loop, then gamescript is back to Deity mode,

I hope I understood it well :)
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 7 guests