Page 1 of 2

Same variable name for all sprites

PostPosted: Mon Nov 05, 2012 6:38 pm
by RBuster
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

Re: Same variable name for all sprites

PostPosted: Mon Nov 05, 2012 7:23 pm
by justifun
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.

Re: Same variable name for all sprites

PostPosted: Mon Nov 05, 2012 7:38 pm
by RBuster

Very clear. Thank you, @justifun

Re: Same variable name for all sprites

PostPosted: Mon Nov 05, 2012 7:45 pm
by RBuster
One problem: I didnīt see this variable in the comparable variables option of System event. Maybe because itīs a local variable?RenatoB2012-11-05 19:47:31

Re: Same variable name for all sprites

PostPosted: Mon Nov 05, 2012 11:43 pm
by Paradox
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.

Re: Same variable name for all sprites

PostPosted: Tue Nov 06, 2012 10:18 am
by RBuster
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

Re: Same variable name for all sprites

PostPosted: Tue Nov 06, 2012 3:37 pm
by justifun
So you want to check them all at once?, in that case put your "check" into a for each (ordered) loop.

Re: Same variable name for all sprites

PostPosted: Tue Nov 06, 2012 6:28 pm
by Paradox
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.

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.)Paradox2012-11-06 18:34:11

Re: Same variable name for all sprites

PostPosted: Tue Nov 06, 2012 6:44 pm
by Arima
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.Arima2012-11-06 18:45:22

Re: Same variable name for all sprites

PostPosted: Tue Nov 06, 2012 7:08 pm
by RBuster
Thanks @justifun and @paradox. Iīll try to implement the justifun suggestion

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