Due to Skylines Game Objects acting like self-contained programs we have a way for object entities and the game systems to communicate with each other. This is done by the use of unique identifiers for locating specific entities. Each entity in the scene has a designated ID and is assigned in a sequential order. This way we can notify an entity that something has happened and/or send some data to the other entity. By using this we can create and control some very complex relationships between Game Objects enabling all sorts of Game Mechanic dynamics.
We can get the ID of an entity in the scene by using its property panel, but this can be an issue. If for whatsoever reason this entity id is changed, due to a scene reordering itself after another object has been deleted. To get around this we advise the use of “Tag Names”.
Other than a scene script, most scripts are attached to an entity. This entity's ID is passed into any attached script in the form of an event argument. It’s common to see the variable “obj” in Skylines scripts. We use this as a global variable, only to this script, containing this parent entity's ID. Now we have this ID we can send it to other objects if requested by them.
Obj = -1; -- Create our global variable to store the objects id. function onInit(objID) -- Event called after you press the play button, this scripts game entry point. obj = objID; -- The id of this object at the time of pressing the play button or end game starting up. end
Now we can use the variable “obj” to represent this entities ID anywhere in this script.
To call communicate with another object we can use a special command to call a function in a target object script, and if required pass some data between these objects. To do so we have a few options (targetID is the id of the object you are calling).
Ok I hear you say “You said don’t use ID’s, use tags instead!” well I did. What we need to do to obtain the “targetID” is use the target objects entity tag property and a neat Lua command to get the id from this tag:
targetID = entity.getIDFromTag("Target_Object_Tag");
More on this inter object communication on the next page →