For test results, bug reports, announcements of new builds etc.
Moderators: winston , another_commander , Getafix
phkb
Impressively Grand Sub-Admiral
Posts: 4830 Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.
Post
by phkb » Fri Feb 26, 2016 1:35 am
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
Posts: 6681 Joined: Wed Feb 28, 2007 7:54 am
Post
by another_commander » Fri Feb 26, 2016 9:25 am
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.
phkb
Impressively Grand Sub-Admiral
Posts: 4830 Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.
Post
by phkb » Fri Feb 26, 2016 9:05 pm
Ah! Thanks a_c! My training in JavaScript continues!