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