Planet properties missing on Mac (solved)

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

Moderators: winston, another_commander, Getafix

Post Reply
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2407
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia

Planet properties missing on Mac (solved)

Post by Wildeblood »

Resolved as a false alarm.

I had an exchange with Knotty last night that went along the lines of:-

Condescending reply from him: That's an interesting idea, after some messing around I got it to work for you.

Irritated reply from me: What the hell do you mean you got it to work? It does work.

It turns out that the same variable in a script is behaving differently on his Mac than my Win7. Specifically, he says that code like this:

Code: Select all

this.$planet = system.mainPlanet;
...
var altitude = (self.position.distanceTo(this.$planet) - this.$planet.radius - self.collisionRadius).toFixed(0);
- 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:-

Code: Select all

this.$position = system.mainPlanet.position;
this.$radius = system.mainPlanet.radius;
...
var altitude = (self.position.distanceTo(this.$position) - this.$radius - self.collisionRadius).toFixed(0);
- to make it work.
Last edited by Wildeblood on Sun Nov 11, 2012 4:23 pm, edited 2 times in total.
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Planet properties missing on Mac (1.76.1)

Post by Thargoid »

The line

Code: Select all

var altitude = (self.position.distanceTo(this.$planet) - this.$planet.radius - self.collisionRadius).toFixed(0);
needs to be

Code: Select all

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.
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Planet properties missing on Mac (1.76.1)

Post by cim »

Thargoid wrote:
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.
http://wiki.alioth.net/index.php/Oolite ... xpressions
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 should work.
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Planet properties missing on Mac (1.76.1)

Post by Thargoid »

It has never done so under Windows - you've always had to use position explicitly.

Which I guess confirms the point originally raised, albeit a limitation we Windows users didn't know we had.
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Planet properties missing on Mac (1.76.1)

Post by cim »

Thargoid wrote:
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)
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Planet properties missing on Mac (1.76.1)

Post by Thargoid »

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.
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2407
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia

Re: Planet properties missing on Mac (1.76.1)

Post by Wildeblood »

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.

PM with download links coming your way.
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: Planet properties missing on Mac (1.76.1)

Post by Eric Walch »

Thargoid wrote:
...... 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. :twisted: ) I would never buy a car, or similar with production date 12-11-20xx.
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Planet properties missing on Mac (solved)

Post by Thargoid »

From the debug console under Windows7:

Code: Select all

> 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]
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2407
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia

Re: Planet properties missing on Mac (solved)

Post by Wildeblood »

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.
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Planet properties missing on Mac (solved)

Post by Thargoid »

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.

As you say, "solved".
Post Reply