system.waypoints not working? (Resolved)

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

Moderators: winston, another_commander, Getafix

Post Reply
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

system.waypoints not working? (Resolved)

Post by phkb »

I'm not sure if this is me or not, but when I run this code:

Code: Select all

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?
Last edited by phkb on Sat Feb 27, 2016 2:53 am, edited 1 time in total.
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6682
Joined: Wed Feb 28, 2007 7:54 am

Re: system.waypoints not working?

Post by another_commander »

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: Select all

Object.keys(system.waypoints).length
will give you the correct result.
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: system.waypoints not working?

Post by phkb »

Ah! Thanks a_c! My training in JavaScript continues!
Post Reply