The reason I ask is this:
From that it looks like a many-to-one relationship, where an object can have several labels, but a label can only have one object.JS API autodocs wrote: 5.7 addLabel(object, label)
Add a label to a game object. If there already is a label by that name, it is overwritten. This is a fast operation of O(log n) algorithmic complexity.
....
5.9 getLabel(object)
Get a label string belonging to a game object. If the object has multiple labels, only the first label found will be returned. If the object has no labels, null is returned. This is a relatively slow operation of O(n) algorithmic complexity.
But there's no easy way to get a list of all labels associated with an object, because getLabel() only returns the first label it finds for the object.
IMHO it would be much simpler to force a 1:1 relationship between labels and objects. This way a .label could be added to applicable objects (droid, structure, feature, area, position). Alternatively, do it the other way round, so a label can refer to many objects, but an object can only have one label?
If prototypal inheritance was used, and the relationship was 1:1, the (super)classes could have a getter/setter property ".label" which when set would trigger addLabel(this,value) and when get would trigger getLabel(this). This would make it very easy to work with labels...
Code: Select all
var label = someDroid.label; // get current label
someDroid.label = "foo"; // add or change the label
// Note: If there's already a "foo" label, it will be updated to point to someDroid