Page 1 of 1
[GS] FGVersionController
Posted: 02 Nov 2013 21:01
by idioty
This library help to use new features of GS, while the old versions of OpenTTD remain supported.
Version 2 is available!
Special thanks for the help of krinn.
And usage is simple:
create an instance of this class (with minimum supported system):
Code: Select all
this.versionController = FGVersionController(1, 3, 1);
and example tests:
Code: Select all
if (this.versionController.IsCurrentVersionLessThan(1, 3, 0) {…}
if (this.versionController.IsCurrentVersionGreatherThanOrEqualTo(1, 3, 0)) {. . .}
Full documentation:
http://feca.homedns.org/documentations/ ... index.html
lastest version available:
Bananas download link:
http://binaries.openttd.org/bananas/gsl ... r-2.tar.gz
Re: [GS] FGVersionController
Posted: 03 Nov 2013 02:48
by krinn
Why hardcoding openttd versions like that, that's somehow strange.
Would be easier (and better no update need when new openttd version is out) to simply :
user_maj = user_maj << 8;
user_min = user_min << 4;
user_version = user_maj + user_min + user_build;
ottd_version = AIController.GetVersion() >> 0x14;
ottd_maj = ottd_version & 0xf00;
ottd_min = ottd_version & 0xf0;
ottd_build = ottd_version & 0xf;
now you can easy compare : ottd_version < user_version...
Re: [GS] FGVersionController
Posted: 03 Nov 2013 08:43
by idioty
Thanks!
That it is a good idea! There's something to learn!
But this does'nt work for me:
Code: Select all
ottd_version = AIController.GetVersion() >> 0x14;
ottd_maj = ottd_version & 0xf00;
ottd_min = ottd_version & 0xf0;
ottd_build = ottd_version & 0xf;
But I found a solution on this forum:
Code: Select all
local v = GSController.GetVersion();
local major = (v & 0xF0000000) >> 28;
local minor = (v & 0x0F000000) >> 24;
local build = (v & 0x00F00000) >> 20;
local release = (v & 0x00080000) != 0;
local revision = v & 0x0007FFFF;
And this work! Thanks again for the replay.
I will write a special thanks for you in the next release
this is the topic:
http://www.tt-forums.net/viewtopic.php? ... on#p787612
Re: [GS] FGVersionController
Posted: 03 Nov 2013 13:11
by krinn
You're welcome.
BTW, did you check AI/GSInfo.GetAPIVersion setting ? Because it should solve the need to check openttd version.
Re: [GS] FGVersionController
Posted: 03 Nov 2013 14:58
by idioty
I do not think is necessary, because I set the minimum was 1.2 Api version.
This is GS only and the GS available only from 1.2 version.
And the user can set the minimum script requirement.
In my game script is 1.3.0 because I need the GSCargoMonitor.
Re: [GS] FGVersionController
Posted: 03 Nov 2013 15:22
by Zuu
An alternative to checking for OpenTTD version is to check for the availability of an API method.
Code: Select all
if ("GetName" in GSTown) { /* do something */ }
If you need to check for an entire class you need to use some magic by krinn included in
SuperLib.Story.IsStoryBookAvailable().
If you plan to check for availability of StoryBook, I recommend using SuperLib.Story.IsStoryBookAvailable() because it will return false for some revisions when the API is available but there was a save/load bug in the Story book feature causing trouble at loading. So it is best to just not use the Story Book feature at those revisions and rely on the above mentioned method to detect if a user has a new enough nighly/release. As long as you obey GPL v2, you can of course copy this check method from SuperLib if you do not want to add it as dependency for just this method.
Re: [GS] FGVersionController
Posted: 03 Nov 2013 20:20
by idioty
I understand, but I think the nigthly edition contains many errors, and users know this.
My source code is included in the new API options, but I do not recommend the use of going live.
And users are aware that (I guess).
Re: [GS] FGVersionController
Posted: 03 Nov 2013 21:16
by Lord Aro
Nightly/trunk usually doesn't actually contain anymore bugs than stable (other than the rare build breaking bugs) I would say a fair proportion of users use nightly as their main version (I do)
Re: [GS] FGVersionController
Posted: 04 Nov 2013 16:34
by idioty
I am also think same way.
And why it's better
Code: Select all
if (("GetName" in GSTown) && ("FoundTown" in GSTown) && ... {}
than
Code: Select all
if (this.versionController.IsCurrentVersionGreatherThanOrEqualTo(1, 4, 0) {}
?
Actually, no matter, I wrote to myself
