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
Commodore
Commodore
Posts: 2343
Joined: Tue Jan 21, 2014 10:37 pm
Location: [p]laying [h]ard and [k]icking [b]utt somewhere in G7...

system.waypoints not working? (Resolved)

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
Quite Grand Sub-Admiral
Posts: 5394
Joined: Wed Feb 28, 2007 7:54 am

Re: system.waypoints not working?

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.

User avatar
phkb
Commodore
Commodore
Posts: 2343
Joined: Tue Jan 21, 2014 10:37 pm
Location: [p]laying [h]ard and [k]icking [b]utt somewhere in G7...

Re: system.waypoints not working?

Post by phkb » Fri Feb 26, 2016 9:05 pm

Ah! Thanks a_c! My training in JavaScript continues!

Post Reply