Access instance variable for multiple instances

Get help using Construct 2

Post » Mon Dec 12, 2016 2:52 pm

I have a simple game in which I need to access the instance variable of some icons in order to have only a specific icon show.
Here is the set up.
I would be so happy if someone could help.
I have 10 icons that are used for click events. This is an animation for which I have 10 frames and each copy is set at a different frame and has a different instance ID from 0 to 9 just like the frame numbers. These are called obj_icon
I have 10 icons (obj_icon2) that are under these with same instance ID. these are used for drag and drop.
Then I have another icon which is a check mark. These have also the same instance ID. Their opacity is 0.

When I drop each icon, there are some feedback on the map. The original icon is detroyed and then the ckeck mark should change opacity. However, I am not sure how to do this because right now it changes all the checkmarks instead of only the one with the same ID as the obj_icon.
Image
Image
Image
Image
B
8
S
1
Posts: 86
Reputation: 618

Post » Mon Dec 12, 2016 2:58 pm

You need to add an event to pick your "other" object that has the same inst_ID as the original.
ImageImageImage
B
71
S
21
G
221
Posts: 3,650
Reputation: 124,229

Post » Mon Dec 12, 2016 3:08 pm

Condition: System>Pick by comparison: "Desired item to be picked" with Item.ID = OverlappedItem.ID
Image
B
104
S
23
G
17
Posts: 1,350
Reputation: 22,028

Post » Mon Dec 12, 2016 7:29 pm

OK! I actually changed thing a little. I added an animation to the obj_icon. I added a variable that is set on the click event to be equal to the obj_icon_ID. then I used:
system Pick obj_icon instance checkIconNum and then set this icon to the animation.

Thank you for directing me to "pick"!
B
8
S
1
Posts: 86
Reputation: 618

Post » Mon Dec 12, 2016 8:52 pm

Actually I am not sure why only part work but not all. As you can see in code below I tried 2 things:
Solution 1: variable checkIconNum is set when clicking on the icon.
Then in the drop event I pick the obj_icon and set it to ID_CHECK
This works but since the obj_icon that has the click event is still there, then you still can click there to bring the question in

Solution 2: I use the checkmark icon (obj_check) and set its inst_ID to checkIconNum
I destroy obj_icon so the click event is destroyed too
I set the opacity of obj_check to 100

Solution 2 does not always work for some reason.

Any idea why? Is the wait even not enough for the system to know what is going on?

Image
B
8
S
1
Posts: 86
Reputation: 618

Post » Mon Dec 12, 2016 10:29 pm

OK. I put the icon on 2 rows to see what happens. for solution 2, I also use pick for the obj_icon since I need to destroy that one too.

But the result is not consistent.
Here is an example:
picked inst 3 - works
picked inst 8 - works
picked inst 0 - works
picked inst 5 - check mark correct but obj_icon instance 9 is destroyed instead of 5 while the text shows 5 correctly.
picked inst 1 - check mark correct but obj_icon instance 2 is destroyed instead of 1 while the text shows 1 correctly.
picked inst 4 - check mark correct but obj_icon instance 8 is destroyed instead of 4 while the text shows 4 correctly.

so this is really bizarre!

Any suggestion why the result is weird?
B
8
S
1
Posts: 86
Reputation: 618


Return to How do I....?

Who is online

Users browsing this forum: Darth Crusher and 2 guests