How do I pick the right object?

Get help using Construct 2

Post » Mon Nov 17, 2014 6:56 am

Hi there,

having some difficulties here...

In my project a block with a random frame number is created every x seconds.
When a player clicks one of the blocks, I have to know which block it was, maybe by using IID's?
However, reading the manual, it says you should not rely on IID's, especially not when sprites are newly created and destroyed.

I'm wondering which is the right track then...
Array? Dictionary? IID's after all?

If the 'problem' is not clear, I can create and post a simple capx to try to make things clear.

Any help would be appreciated...
Thanks in advance!
Image
B
54
S
24
G
12
Posts: 96
Reputation: 10,326

Post » Mon Nov 17, 2014 7:28 am

Your clicked event automatically picks the clicked block.

e.g.

Mouse: On Left button Clicked on Sprite -> Sprite: <do something>

The 'Sprite: <do something>' is already the correct object for you.

Or maybe you mean something deeper..
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Mon Nov 17, 2014 8:23 am

Hi Codah,

thanks for your quick reply.
Yes, I'm 'afraid' it goes a bit deeper ;)

I need to know the ID of each block since the blocks have bullet behaviour from left to right.
The sooner the player clicks on the block, the more points he's awarded.
Thinking about it, maybe I have to check the ID if the block AFTER the player has clicked it and only then apply actions to it...

I'll test with this option, but should you have any suggestions, please feel free to post them :)
Image
B
54
S
24
G
12
Posts: 96
Reputation: 10,326

Post » Mon Nov 17, 2014 9:02 am

I still don't understand ... Just have an instance variable on each block, that should be enough to choose between them. But I'm really not sure, maybe you can post a sample capx.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Wed Nov 19, 2014 10:46 am

I've been trying and testing but can't seem to get it together.
It seems I'm just missing one step or simple thing...

Hope you (or anyone else) can help me out...

What's going on:
at the top middle of the screen there's a textbox.
On start of layout this textbox displays a random color (red, black or blue).
Whenever a block with this color is clicked, it should disappear.

That's all there is to it, except one way or another my brains are 'blocking' ;)
You do not have the required permissions to view the files attached to this post.
Image
B
54
S
24
G
12
Posts: 96
Reputation: 10,326

Post » Wed Nov 19, 2014 11:15 am

@Rjan:
you have to set the Color instance variable matching the current animation frame. And then you test this instance variable against the color to pick.

Image

Have fun
B
19
S
2
G
1
Posts: 24
Reputation: 1,475

Post » Wed Nov 19, 2014 11:22 am

Damn moonworX!
Life can be soooo simple.... :D

Thanks a whole lot for your fast and excellent help!
Image
B
54
S
24
G
12
Posts: 96
Reputation: 10,326


Return to How do I....?

Who is online

Users browsing this forum: danalog and 25 guests