Same variable name for all sprites

0 favourites
  • 10 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • I intend to use a different enemies with the same local variable (numLife). I would like to check the life bar of these sprites at sigle time (eg. enemyObject.numLife) . How can I do this?

    Thanks

  • Yeah you've got it correct.

    the variable will be objectname.varname

    so for example

    system every tick -> No action

    (sub event) system compare instance variable enemy.numlife <1 --> destroy

    now any time a enemies life = 0 it will get destroyed.

  • Very clear. Thank you, justifun

  • One problem: I didn?t see this variable in the comparable variables option of System event. Maybe because it?s a local variable?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • That's because the variable comparison for a sprites instance variable is under the sprite, not the system.

    Click on the sprite, and look for the "Instance Variable" heading. you will find the comparison there.

  • Hi Paradox,

    This I already knew. The problem is that this way I have to create the command for each sprite and I would like to create a general command to verify all objects at once

  • So you want to check them all at once?, in that case put your "check" into a for each (ordered) loop.

  • If all of them are picked, (you didn't filter any out with events,) it should still work on all of them. "For each" is assumed.

    I would be 100% sure of that if I hadn't just read Justifun's suggestion. <img src="smileys/smiley4.gif" border="0" align="middle" />

    Edit: I see, you meant you do have some filtered? It works the same way as a system version would, they both act on what is picked. (all top events start with everything picked, and you filter down to the ones you want to work on. However you can use "Pick All" to reset the picking list.)

  • I think what you want are families. They're basically a group of objects that acts like an object itself, meaning you can also give the family a variable, resulting in all of the group's objects getting that variable as well.

    That way you can check the variable for a bunch of objects with one condition.

  • Thanks justifun and I?ll try to implement the justifun suggestion

    You?re right, But it?s ony available in personal/commercial version. I?ll intend to buy the C2 very soon.

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