Ylands Tutorial - Labels

From Bohemia Interactive Community
Jump to navigation Jump to search


Labels are … well… labels. Every label is defined by a Entity Label Game Logic (or Game Label) you put into scene. You can attach as many labels to an object as you want. This comes in handy in two ways - firstly you can check any object for any labels attached to it. It’s an easy and effective way to store the information about the entity - you can, for example, attach label name Visited to any Trigger Zone you visit. Enemy label to entities that you consider enemies… and much more.


The second thing you can do with labels is that you can you have an array filled with entities that have a specified Label attached to them. This way you can quickly get a list of enemies, visited Trigger zones etc.


You can attach/remove labels to object both in the Editor (even to many at once) or via script.


Note:

It matters whether you’re working with Entities or Game Logic objects - both use specific type of labels as well as instructions. Trying to use incorrect type of object with a label will result in an error.


Note:

When working with a label, the order of the entities it contains is not deterministic, meaning that you can't rely on some entity always keep its position in the array you get when getting all entities with the given label.


The Hats

All the hats have a single Label attached to them so we can easily get their list as an array. When the player clicks the button, a random hat is selected from this array and equipped.


The Random Objects

When a player presses the button, all objects sharing the specific label will change its color.


The Trigger Zones

Here we have a lot of Trigger Zones and want to know, which have been already visited by the player. One way would be to define a variable in each of them and set it to true when its entered. Doing that, however, is not a good design because it is alway better to find a solution that requires editing of as few objects as possible.


The way we do it is that we have an Event Listener. Whenever it detects player entering a Trigger Zone, it checks whether it has the specific “Visited” label attached to it. If not, it means the player has entered it for the first time (and we attach the label).