Why I can't pick an object?

Get help using Construct 2

Post » Mon Oct 17, 2016 1:16 pm

Hi, guys
I use for loop to create multiple objects and set instance variable that called "ID", I want to pick two consecutive objects, so I use "pick by comparison" to pick them. But I can not pick them.
Something was wrong?
Image
Here is my capx https://drive.google.com/uc?export=download&id=0B8g2b8f9ktNBLTd1T2xWam9QX1U
B
32
S
16
G
18
Posts: 57
Reputation: 11,658

Post » Mon Oct 17, 2016 2:10 pm

pls, help me?
B
32
S
16
G
18
Posts: 57
Reputation: 11,658

Post » Mon Oct 17, 2016 2:23 pm

The problem with your setup is the second pick condition.

The first pick condition
Code: Select all
Pick Sprite where Sprite.ID = loopindex("a2")
works fine and selects the corresponding Sprite.

The thing is that the second pick condition
Code: Select all
Pick SpriteFM (family) where SpriteFM.ID = loopindex("a2")+1
from the previously picked objects picks.
This means that the first pick reduces the picked objects to one Sprite that has the right ID.
The second pick condition picks the Sprite that has a different ID.
Since there is no Sprite which has two different IDs at the same time, there isn't any Sprite picked and that's why the text doesn't change.

Now to fix this, you could either just disable the second pick condition
or
you could add a second text object, then move the second pick condition to be checked after the first one (as sub-event to the loop) but not as a sub-event of the first pick. You would then change the second text to the second Sprite.ID.

Hope I could help.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Mon Oct 17, 2016 3:47 pm

randomly wrote:The problem with your setup is the second pick condition.

The first pick condition
Code: Select all
Pick Sprite where Sprite.ID = loopindex("a2")
works fine and selects the corresponding Sprite.

The thing is that the second pick condition
Code: Select all
Pick SpriteFM (family) where SpriteFM.ID = loopindex("a2")+1
from the previously picked objects picks.
This means that the first pick reduces the picked objects to one Sprite that has the right ID.
The second pick condition picks the Sprite that has a different ID.
Since there is no Sprite which has two different IDs at the same time, there isn't any Sprite picked and that's why the text doesn't change.

Now to fix this, you could either just disable the second pick condition
or
you could add a second text object, then move the second pick condition to be checked after the first one (as sub-event to the loop) but not as a sub-event of the first pick. You would then change the second text to the second Sprite.ID.

Hope I could help.

Thank you for your reply. I think all the Sprite are created in the first for loop(10 Sprite with instance variables ID: 1 to 10, I see them in the debug mode). So, I think I can pick them in the second for loop. But nothing happened.

What is wrong with my thinking?
B
32
S
16
G
18
Posts: 57
Reputation: 11,658

Post » Mon Oct 17, 2016 4:15 pm

C2 doesn't let you pick newly created objects until the next top level event. Add a second On start of layout, and move your a2 loop there. It then works.
ImageImageImage
B
71
S
21
G
221
Posts: 3,649
Reputation: 124,227

Post » Tue Oct 18, 2016 1:27 am

blackhornet wrote:C2 doesn't let you pick newly created objects until the next top level event. Add a second On start of layout, and move your a2 loop there. It then works.

Thank you for your reply, I try to call "a2" loop by a function, nothing happened. So, I want to know what is "the next top level event"
B
32
S
16
G
18
Posts: 57
Reputation: 11,658

Post » Tue Oct 18, 2016 3:17 am

Image
ImageImageImage
B
71
S
21
G
221
Posts: 3,649
Reputation: 124,227


Return to How do I....?

Who is online

Users browsing this forum: Bobbyneal100, georeb, Google [Bot], part12studios and 7 guests