- does not work, because this.$planet.position (which I don't specifically use) is wrong and this.$planet.radius returns 0. He needs to use code similar to this:-
var altitude = (self.position.distanceTo(this.$planet.position) - this.$planet.radius - self.collisionRadius).toFixed(0);
distanceTo is the distance between two co-ordinates (in this case two position vector points), whereas your upper one is trying to replace one of those with an entity. I agree it should be fairly obvious that you mean the position of the entity, but JS as you well know is a stickler for such details.
Your second version is essentially the above written in a slightly different way, and should work. For me the fact that the distanceTo with an entity rather than a vector works in Mac is a little surprising. I can't comment on the radius bit without some testing, but I can't see why that should return 0 based on your code (which isn't to say it doesn't via a bug).[/color]
Last edited by Thargoid on Sun Nov 11, 2012 8:44 am, edited 1 time in total.
Your second version is essentially the above written in a slightly different way, and should work. For me the fact that the distanceTo with an entity rather than a vector works in Mac is a little surprising.
All Oolite-provided functions which take a vector as an argument may instead be passed an array of three numbers, or an Entity (in which case the entity’s position is used). In specifications, this is represented by arguments typed vectorExpression.
It has never done so under Windows - you've always had to use position explicitly.
I would be very surprised by that. Wildeblood is using Windows 7 and has it working, and it's not functionality that should depend on the OS.
If this.$planet.radius = 0, that suggests something is going wrong with the this.$planet reference.
What does log(this.name,this.$planet); produce?
(Wild guess based on what code is visible: this.$planet is set in the script, and then a witchspace jump is made without resetting it. this.$planet is then pointing to an invalid entity and its properties are meaningless. Saving the position and radius values at the start avoids that, sort of)
I've had code choke on me before because I forgot the position part - hence the comment. At least that's my memory, which if of course never the best thing on a Sunday morning.
Thargoid: I'm the one with Win7 and it works without specifically checking the .position property. Knotty says that doesn't work for him on a Mac. I was surprised it worked like that, but I copied it from an example Eric posted about 18 months ago.
cim wrote:
(Wild guess based on what code is visible: this.$planet is set in the script, and then a witchspace jump is made without resetting it. this.$planet is then pointing to an invalid entity and its properties are meaningless. Saving the position and radius values at the start avoids that, sort of)
Cim: Nuh. Launch and fly down to planet. I initially suspected System Redux was messing about with it, but he says the problem persists with only my WIP and no other OXPs.
this.$planet is set in .startUp. Should I move it to outside .startUp (does system.mainStation exist before .startUp?) or to .shipWillLaunchFromStation?
No, it isn't. I was thinking of another similar script. This is a ship script.
...... my memory, which if of course never the best thing on a Sunday morning.
Today it is the 11th day of the 11th month. So, I guess it will even be worse on monday morning...... (At least in some parts of the world. ) I would never buy a car, or similar with production date 12-11-20xx.
> PS.position.distanceTo(S.mainPlanet.position)
94816.88824141496
> PS.position.distanceTo(S.mainPlanet)
94816.88824141496
> PS.distanceTo(S.mainPlanet)
Exception: TypeError: PS.distanceTo is not a function
Active script: oolite-debug-console 1.77
oolite-debug-console.js, line 844:
}
> S.mainPlanet.distanceTo(player.ship)
Exception: TypeError: S.mainPlanet.distanceTo is not a function
Active script: oolite-debug-console 1.77
oolite-debug-console.js, line 844:
}
So removing the position from the planet entity works, but it doesn't seem to for the player.ship entity?
Perhaps I'm only half-mad, but at least in the console it's not entirely working even under Windows either.[/color]
That's working correctly. You're forgetting the importance of the (). They mean evaluate what is within.
In A.position.distanceTo(B) B is evaluated, A is not. You're attempting to do A.distanceTo(B), but A is never evaluated to find its position. distanceTo() is a function of positions, not of entities.
A good point. I've only hit it by mistake when I've mistyped the script entry (and forgotten the .position in the first point. It just rang a bell as similar to what you originally mentioned, but you are correct that it's subtly different.