Oolite Bulletins

For information and discussion about Oolite.
It is currently Sun Jun 25, 2017 10:31 am

All times are UTC




Post new topic  Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Fri Feb 26, 2016 1:35 am 
Offline
Commodore
Commodore
User avatar

Joined: Tue Jan 21, 2014 10:37 pm
Posts: 1518
Location: [p]laying [h]ard and [k]icking [b]utt somewhere in G7...
I'm not sure if this is me or not, but when I run this code:
Code:
system.setWaypoint(
	this.name, player.ship.position, player.ship.orientation,
	{size:50, beaconCode:"T", beaconLabel:"Test"}
);
player.consoleMessage("Waypoints in system: " + system.waypoints.length, 10);
I'm expecting to see "Waypoints in system: 1" appear on the console. But instead I get "Waypoints in system: undefined".

Am I doing something wrong, or is there a problem with the system.waypoints array?

_________________
My OXP's


Last edited by phkb on Sat Feb 27, 2016 2:53 am, edited 1 time in total.

Top
   
PostPosted: Fri Feb 26, 2016 9:25 am 
Offline
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral

Joined: Wed Feb 28, 2007 7:54 am
Posts: 4853
system.waypoints is a dictionary, not an array. So trying to get the length directly will lead to error. What you can do instead is get the array of keys in the waypoints dictionary and count its elements.
Code:
Object.keys(system.waypoints).length
will give you the correct result.


Top
   
PostPosted: Fri Feb 26, 2016 9:05 pm 
Offline
Commodore
Commodore
User avatar

Joined: Tue Jan 21, 2014 10:37 pm
Posts: 1518
Location: [p]laying [h]ard and [k]icking [b]utt somewhere in G7...
Ah! Thanks a_c! My training in JavaScript continues!

_________________
My OXP's


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
Powered by phpBB® Forum Software © phpBB Limited