How do I reference an object by its name

Get help using Construct 2

Post » Thu Mar 06, 2014 1:34 pm

Hi all,

I'm really new to Construct 2 and I wonder if it's possible to reference an object by its name.

let's say I have a spritePlayer1 and I want to know if it collides with a spriteWall.
In this case I only have to set the condition:

if spitePlayer1 collides with spriteWall then do something....

But what if I have more spritePlayer? 10, 50, 100???

is it possible to reference those sprites by its name so I dont have to set a condition for each spritePlayer???

if spritePlayer.name="five" collides with spriteWall then do something..

Thanks in advance...
B
4
Posts: 16
Reputation: 232

Post » Thu Mar 06, 2014 1:40 pm

It's done automagically (refer to the "picking" section of the manual).

Whenever a condition for an instance of your spritePlayer is true, that specific instance gets picked. So whatever action you start then works on that picked instance.

*Edit: I made you a little example. The green ones are your spritePlayers.

http://baconland.de/stuff/picking.capx
B
79
S
29
G
32
Posts: 482
Reputation: 19,915

Post » Thu Mar 06, 2014 3:09 pm

Thanks for your reply!,
In your example all the good ones are an instance of the same object and have the same name, right?

But I was wondering if it is possibe to do it with different objects, as in your example lets say we have 3 different good ones (square, circle, triangle)
B
4
Posts: 16
Reputation: 232

Post » Thu Mar 06, 2014 3:12 pm

Then you would stick them in a family and check against that one.

https://www.scirra.com/manual/142/families
B
79
S
29
G
32
Posts: 482
Reputation: 19,915

Post » Thu Mar 06, 2014 5:10 pm

Oh thanks again, families would help!!
didn't know that feature in Construct 2....
B
4
Posts: 16
Reputation: 232

Post » Thu Mar 06, 2014 6:06 pm

The whole families concept needs some time to get used to, so don't be alarmed if it doesn't work on the first try ;-)
B
79
S
29
G
32
Posts: 482
Reputation: 19,915


Return to How do I....?

Who is online

Users browsing this forum: dop2000, Maako, max2612 and 9 guests