compareVersion

For test results, bug reports, announcements of new builds etc.

Moderators: winston, another_commander, Getafix

Post Reply
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

compareVersion

Post by Eric Walch »

The function compareVersion is not working as described in the wiki:
wiki wrote:
Compare the version of Oolite to versionSpec, which may be either a string or an array. If the current version of Oolite is less than versionSpec, -1 is returned. If the current version of Oolite is greater than versionSpec, 1 is returned. If they are equal, 0 is returned.
It reacts just the other way: oolite.compareVersion("1.71") returns +1 with Oolite 1.70, not -1 as advertised.
I want to use it to make sure my code runs not on 1.69, but must know if the documentation will be changed or the code.

Changing the wiki is the best when 1.69 also behaved this way.


Also found a error in the wiki for marksystem(s) and unmarkSystem(s). Is should be without the ending "s". I changed this in the wiki as I assume the code stays this way. markSystem() will also accept a row of systems to mark in one single command. unmarkSystem will work from 1.71 onwards.
Last edited by Eric Walch on Tue Jan 29, 2008 10:38 pm, edited 2 times in total.
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Post by Kaks »

Aha, I had the very same problem with making the new version of transports.oxp compatible with 1.68 & 1.69, and the compareVersion does work 'in reverse.

However, comparing versions - and the 'oolite' object in javascript - is only supposed to work in 1.70 & up, afaik. But it might work in 1.69 too.

I've only been able to test 1.68, 1.70 & svn build. Unfortunately, I cleverly deleted my backup copy of 1.69 & berlios doesn't host it anymore.

Here's my cover-all-possible-angles version checker:

Code: Select all

this.minOolite="1.65"; //include any homebrew js enabled oolites.
//this.badOolite=[]; //no bad oolites. Yay!
this.badOolite=["1.70"];//example for 2 bad Oolites: ["1.70","1.71"] 

function canRun(name,minOolite,badOolite){ //string, string, array
	//oolite not defined in v1.68, needs the try/catch clause
	try{
		if (!oolite) return (minOolite-0<1.7); 
	} catch(err){ return (minOolite-0<1.7);}
	if (oolite.compareVersion(minOolite) > 0){
		LogWithClass("script."+name, "--- Script disabled. Script requires Oolite v"+minOolite);
		return false;
	}
	for (var i in badOolite){
		if (oolite.compareVersion(badOolite[i]) == 0){
			LogWithClass("script."+name, "--- Script disabled to avoid bugs in Oolite v"+oolite.versionString+". Please use another version. ");
			return false;
		}
	}
	return true;
};
this.startUp = this.reset = function(){
	if (!canRun(this.name,this.minOolite,this.badOolite)){
		delete this.shipLaunchedFromStation;
		delete this.shipExitedWitchspace;
		//also remove 1.68 & 1.69 events!
		delete this.didLaunch;
		delete this.didExitWitchSpace;
	}
}

this.didLaunch = this.shipLaunchedFromStation = function(){

//blah blah blah

}

this.didExitWitchSpace = this.shipExitedWitchspace = function(){


//blah blah blah

}

Assigning the same function to old & new style event works ok, it fires only once in 1.70 & up, and in 1.69.1 the new style event is simply ignored.

There's also a simpler simpler option:

Code: Select all

this.startUp = this.reset = function(){
	var pre170;
	try{
		pre170=!oolite;
	}catch(err){pre170=true;}

	if pre170{
		//pre 1.70 stuff

	} else {
		//version comparison using oolite.compareVersion()

	}
}
Hope this helps!

Kaks
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Post by Eric Walch »

Here's my cover-all-possible-angles version checker:
I created something similar to prevent that JS code runs on 1.69.1. But the problem solved itself. 1.69 detects script errors and discards the code as a whole. Not the way iI intended, but the result counts. My minimum version stays 1.65 this way.
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post by JensAyton »

Hmm, I guess I confused myself. It’s not hugely important which way around it is, so I’ll update the documentation to match reality.
Post Reply