Page 1 of 1

[help] How to create global goal ?

Posted: 21 Apr 2014 10:22
by hpfx
Hello,

I try to create a global goal, I start with API documentation http://nogo.openttd.org/api/1.4.0/class ... 0645b67467

Code: Select all

GSGoal.New(company, goal, type, destination)
But this is not enough to help me.
I can read that I must use GSCompany::COMPANY_INVALID as company, ok.
I'm not sure which GoalType I must use for "global goal", I pick GT_NONE.
but what is destination ? it's not clearly explained. I guess destination is a town when GoalType is GT_TOWN (same with industry) but other case ? I guess I must leave it zero... it's not explained.

Here is what I tried :

Code: Select all

GSGoal.New(GSCompany.COMPANY_INVALID,GSText.STR_GOAL1,GSGoal.GT_NONE, 0);

it does not gives any error, but I cannot see any goal.
I tried also this one :

Code: Select all

GSGoal.New(GSCompany.COMPANY_INVALID,GSText.STR_GOAL1,GSGoal.GT_COMPANY, 0);
still no goal...

I searched for "GSGoal.New" on wiki and in this forum, without any success... I'm wondering how you create goals ? are API texts enough for you ? please tell me what's wrong ?


Also this sentence makes me troubles :
Global goals can only reference global story pages

I guess story page are a part of story book.
But I don't want to have story book at all,
I played multiplayer games which had global goal without storybook. (I don't know the name of the script btw)
Then I think it's only relevant for GT_STORY_PAGE type, which is not what I want.

sorry, I feel too dummy.
than kyou for your help.

Re: [help] How to create global goal ?

Posted: 21 Apr 2014 10:50
by frosch
Try

Code: Select all

GSGoal.New(GSCompany.COMPANY_INVALID, GSText(GSText.STR_GOAL1), GSGoal.GT_NONE, 0);

Re: [help] How to create global goal ?

Posted: 21 Apr 2014 11:14
by hpfx
frosch wrote:Try

Code: Select all

GSGoal.New(GSCompany.COMPANY_INVALID, GSText(GSText.STR_GOAL1), GSGoal.GT_NONE, 0);
Well, now I feel dummy... it was so simple :)

thank you frosch.

but I have a question : is destination only used for GT_TILE, GT_INDUSTRY and GT_TOWN ?

Re: [help] How to create global goal ?

Posted: 21 Apr 2014 16:11
by Zuu
Destination is used by all types except for DT_NONE.

For the story page type, destination is the page id of a story book page. If you create a global goal it cannot reference company specific pages. Only global ones.

Re: [help] How to create global goal ?

Posted: 21 Apr 2014 20:37
by hpfx
thank you,

One more question about goals,
I used to return "1.3" in GetAPIVersion(), because my GS is supposed to be compatible with version 1.3 and 1.4

Code: Select all

class FMainClass extends GSInfo {
	function GetAPIVersion()	{ return "1.3"; }
...
}
And when I want to mark the goal as completed, I used this kind of code :

Code: Select all

if(isVersion14ormore()) // only for ottd 1.4+
{
 GSGoal.SetProgress(goalId,"OK");
 GSGoal.SetCompleted(goalId,true); // do nothing ?
}
But because GetAPIVersion() is returning "1.3", both SetProgress() and SetCompleted() were not proceed. (even if isVersion14ormore() returned true on ottd version 1.4)
Then I had to return "1.4" to make it work...

But then, obviously, only by returning "1.4" my script is no more available on ottd 1.3 (I cannot find it anymore on scripts selection)

Is it possible to have the script running on both version, but with progress function to work on 1.4 only ?

Last question : when I use GSGoal.SetCompleted(), nothing changes, don't you visually see the goal is completed ?
Thank you.

Re: [help] How to create global goal ?

Posted: 22 Apr 2014 08:01
by Zuu
Completed goals get a green colour in the progress column and a different icon when referenced from the story book.

In general it is possible to use newer APIs even if you return an older API version with the issue that you yourself have to safe guard or provide code for compatibility with more APIs. However this is not a promise from OpenTTD as far as I understand but more a side effect of how backwards compatibility is implemented. I do however not see (without inspecting code) see why it would fail in your case.

Re: [help] How to create global goal ?

Posted: 22 Apr 2014 10:29
by krinn
hpfx wrote: But because GetAPIVersion() is returning "1.3", both SetProgress() and SetCompleted() were not proceed. (even if isVersion14ormore() returned true on ottd version 1.4)
Then I had to return "1.4" to make it work...

But then, obviously, only by returning "1.4" my script is no more available on ottd 1.3 (I cannot find it anymore on scripts selection)

Is it possible to have the script running on both version, but with progress function to work on 1.4 only ?
Easy to do, first set GetAPIVersion to return 1.3, as 1.3 or 1.4 will see it, else only 1.4 will see it.
Next to that, don't use GetAPIVersion for your checking, just build your own version check.

Code: Select all

function isVersion14ormore () { return ("SetProgress" in GSGoal); }

Re: [help] How to create global goal ?

Posted: 22 Apr 2014 20:20
by hpfx
thank you very much,
you rocks, guys !