How do I check all sprites for instance variable value?

0 favourites
  • 8 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Hi

    I have a project with 5 sprite objects. Each has an instance variable called "moving" for which the default value is 0. During game play several instances of each of these 5 sprites are created. One and only one of them will have instance variable "moving" set to 1. How do I find and pick that single instance? Is there a way to check all of them in a single event or do I have to do it sprite by sprite and thus have at least 5 events (because of 5 sprites)?

    Thank you

  • 5 events unless you add them all to a family and change the moving variable to a family instance variable, then you can check for each family object, where family.moving is 1.

  • I tried with families but then all instances of a sprite got the moving variable set to 1, instead of just one instance of one sprite...

    5 events it is apparently :) thank you

  • If you use system pick a random instance of 'family' then it should pick just the one random instance for 1.

  • This example creates 5 sprites, randomly sets one sprite's instance variable (sprite.moving) to 1

    Then every 1 second destroys a random sprite and creates another one.

    If the sprite's instance variable (sprite.moving) is set to 1 it will rotate it to 45 degrees.

    You can change the number of sprites easily, so 500 sprites would still only be 7 events.

    Hope this is helpful.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Plinkie I tried, but I can't get the expression to pick the one instance with 1. Family doesn't have instance variable, only the objects in the family have it.

    Sizcoz thank you for your example but it has only 1 sprite object and then instances of the same object. I have 5 sprite objects (meaning Sprite1, Sprite2, Sprite3, Sprite4, Sprite5) and then several instances of each of these...

  • Yep will only work if you move the instance variable to be a family instance variable as mentioned above. You have to careful when moving it if you are already using it in events. Once it's a family instance variable, the objects inherit it anyway, and you can pick family with family.variable.

  • ok, getting the hang of it now :) thank you plinkie

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