Understanding UID, IID, Health, Cards and Rocket smoke trail.

3

Stats

13,998 visits, 21,903 views

Tools

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 16 Aug, 2012. Last updated 19 Feb, 2019

Introduction

Here you'll learn the basic of how "UID" and "IID" works, also, how the health of the enemy works.

Who never tried to setup a rocket with smoke trail?

And who never stuck on it while thinking how to setup the smoke to coincide with the rocket when creating it?

All these issues are interrelated and the solution is very easy, you just need some principles.

UID and IID

When you run the game, it create all the objects placed on the canvas, giving them a Unique ID (UID) and a Index ID (IID). They will change when you destroy or create a new object on the canvas.

All the issues and a better explanation about these two is placed on the Manual.

Ashley words:

"IIDs and UIDs in the editor don't change depending on the Z order, but they do change if you delete and insert instances. Because of this you should not rely on knowing UIDs or IIDs in advance at all - the instance with UID 3, for example, could change to a different object if you add or delete some things in the layout view. This could easily break your game or make it work differently "randomly" (it will seem random to many users because they won't realise certain things they did changed the UIDs and IIDs). For this reason I don't think UIDs or IIDs should ever be displayed in the editor, in order to discourage this bad practice."

As said, UIDs and IIDs are necessary for the Engine, but you don't need to rely at all about them.

Instead of using UIDs and IIDs, you should use conditionals where only the wanted object can meet.

Call it by encapsulate an object.

Encapsulating Objects

Let's start with a single example of a Rocket.

Resource file: Instance.CAPX

HTML5: Live sample

Procedure

Minuteness

The procedure above show how to creating the rockets and place the smoke on their tail.

Every time the Engine create a new object, instead of picking their UID or IID (what can change on their life, and shuffle your ordering), it add +1 to a instance variable of a fixed object on your canvas, as an index.

The fixed object here is the text, but you can use an invisible sprite, or, a HUD object.

On created, the conditionals set to the rocket instance variable that index, giving him an unique ID instance.

Also, set the same index to the child smoke (child because the smoke 1 was created by the rocket 1, so, the rocket 1 is parent of smoke 1).

On destroyed, the conditional requires the smoke ID, and destroy only the smoke with the same ID of the rocket.

Because all the IDs are really unique, you don't need to rely about shuffling issues.

The same thing works with a HUGE amount of issues.

For example, when a Orc pick a weapon on the ground, now you can know what weapon was picked, because when you create this weapon, you'll give it the same ID of the Orc ID, then, when the Orc is destroyed, you can set to the weapon be destroyed too.

You can make a poker game, giving for each card an ID, where the ID can setup the frame position and show the right card. Now you can shuffle the cards without worrying about destroying them.

Make special rewards for Unique monsters and making him glow just turning an invisible effect to be visible when the variable ID meet a certain conditional.

And, my favorite, it works perfectly for achievements. ^^

All this explain what means "Encapsulating the Object", but still missing to explain about the health.

When you check if a rocket hit an enemy, them set the enemy life to subtract 1, you're encapsulating the event to that specific enemy.

I think it covered all the proposed on the title, sorry if it's too high language (it means poor language on the programming field) or garbage, but I'm surely it will help someone having their first contacts with Construct 2!

This is a new simple sample of card shuffling and instance IDs manipulation:

http://www.scirra.com/arcade/example/1837/dealing-with-instance-variables

More samples:

Dealing with multiply enemies, how you can set their ID and manipulate each one:

Download the CAPX

Live Sample

https://dl.dropboxusercontent.com/u/47035927/Samples/IDs/sample2/index.html

https://dl.dropboxusercontent.com/u/47035927/Samples/IDs/sample2/filtering_IDs.capx

  • 2 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • Hi, does anyone have the .capx files for the latter examples? The files are no longer hosted on dropbox and I'm in need of help with regards to using and manipulating objects based on UIDs

  • The sample files are no longer downloadable - could these please be updated! Really needing the multiply enemies and set their ID to manipulate each one! Please!