How do I know which instance has which IID?

Get help using Construct 2

Post » Sun Jan 08, 2012 10:38 pm

If I've placed 5 objects (say, of Object type 'Cat') on a layer, how can I know which Cat has which IID? Or to put it another way, if I pick Cat instance 1, how do I know which Cat I'm picking?

The IID for a particular Cat instance is not shown in the Properties Bar (because the IID is allocated at runtime?), so how can I pick it with certainty when I add a condition that will target an action on that Cat instance alone?
B
105
S
20
G
12
Posts: 549
Reputation: 20,320

Post » Sun Jan 08, 2012 10:45 pm

If you have a cat object with platform behavior and a boolean instance variable named 'selected'
You can do that:
[code]System: On start of layout
-> Cat: Start ignoring Platform user input
Mouse: On left cliced on Cat
-> Cat: Set selected to True
Mouse: On right click
Cat: is Selected
-> Cat: Jump[/code]
If you click on a cat and then right click, only the cat on which you clicked will jump.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Sun Jan 08, 2012 10:57 pm

@Yann thanks for the instant reply!

I can see that that would work when there's user interaction with the cats. But what if there's no user interaction and it's the system that's doing the selection?

For instance (!), if Cat objects have a Boolean 'favorite' instance variable that's set by the system for one particular cat when a new level is reached, or the game is replayed, or a certain time has passed, how can I add a condition that targets that Cat instance (and that alone) ?
B
105
S
20
G
12
Posts: 549
Reputation: 20,320

Post » Sun Jan 08, 2012 11:13 pm

[code]
System: On start of layout
.. System : Pick random Cat Instance
   -> Cat: Set boolean to true

Cat: is boolean
-> Cat: This is the cat you want
[/code]

Assuming all cats Boolean are set to false on start of the layout.
This is the usual picking with variable.Kyatric2012-01-08 23:15:01
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Sun Jan 08, 2012 11:27 pm

@Kyatric Thanks for your rapid response!

... but I want to get the system to pick a particular Cat instance (say, the black one), not a random instance. How do I do that? How do I know what IID the black cat has?
B
105
S
20
G
12
Posts: 549
Reputation: 20,320

Post » Sun Jan 08, 2012 11:40 pm

I think we are running a bit in circle, you should explain a bit more what is your game.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Mon Jan 09, 2012 12:33 am

Same thing actualy.
Compare the value of an instance variable that you set in the IDE. (ex: instance variable index, value 0 to 4 (for 5 instances))
Or they have different animation frames ?
Compare the animation frame.

It's all the same logic that picks only the instances that match with the condition.

A look back at how events work might be useful here.Kyatric2012-01-09 00:36:50
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Mon Jan 09, 2012 2:52 am

@Kyatric "Compare the value of an instance variable that you set in the IDE".

Thanks, I'm aware that you can do it by comparing instance variables, but that seems to me to be a roundabout way of identifying a particular instance in a system condition.

I was hoping that there's some more direct way of knowing the IID of each instance and being able to use that.

For example, let's say my layout has a cat in each corner and a cat in the centre. Is there any way I can tell what the IID is of the cat in the centre?

In JavaScript, they'd each have different names (e.g. centreCat, topLeftCat, ...) and I could say 'centreCat.favorite = true' (with all the cornerCats having their 'favorite' Boolean set to 'false').

So another way of asking my question is:
How do I program 'centreCat.favorite = true' in Construct 2?
B
105
S
20
G
12
Posts: 549
Reputation: 20,320

Post » Mon Jan 09, 2012 3:56 am

In my opinion you're asking the wrong question.
But I don't mean to be rude :D

I see many ways to do what you ask, but all these ways aren't the best way depending on what you want to use your cat for.

If you want to pick a cat with the mouse and make it do something my solution works well.
If you want to apply some action on a black cat but not on the other ones, you can use their animation frame or name ('cause it would be different to show differnt colors') to pick them.
If you want to pick the centered cat, you can compare it's position.

If you want to pick a cat precisely, amongst the same kind of cats (same graphics) whereever it is...
First let me say that I don't see the point to be so specific.
But let say you want to be, you just have to do what Kyat said and assign ID in instance variables at runtime.

Also, if you want to memorize a picking for later uses. Let say you selected one cat at the start of the game, the cat gets hidden under mugs and the mugs get shuffled (like these street performance you know?) you can maybe store its UID in a global variable at runtime and pick by UID afterward.
But in this example I would just simply set a boolean to true on this specific cat when you select it.

Now I hope you understand why I said that you should explain a bit more about your game. We need context to provide the optimal answer.Yann2012-01-09 03:59:00
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Mon Jan 09, 2012 8:30 am

IIDs are not constant - they change as you destroy and create objects, so you can never be certain that an IID refers to a specific instance.

You probably want to use UIDs instead, which permanently refer to a single instance. More info in the manual.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Next

Return to How do I....?

Who is online

Users browsing this forum: chrisinfinger, DemantDigitalArt, farfetchd83, mjj1990, spcsmrf and 8 guests