Access instance variable for multiple instances

0 favourites
  • 6 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • 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.

  • You need to add an event to pick your "other" object that has the same inst_ID as the original.

  • Condition: System>Pick by comparison: "Desired item to be picked" with Item.ID = OverlappedItem.ID

  • 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"!

  • 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?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)