Instance Variables & Enemy Health

Just started using Construct 2? Post your questions here

Post » Sat Apr 29, 2017 9:05 am

Image

I just realized, if I have one of these enemies show up, will it inadvertently heal all other instances with this command?

How can I tell if I'm affecting one or all instances of something, and how can I make sure I'm affecting one- or all instances of something?
B
10
S
3
Posts: 10
Reputation: 670

Post » Sat Apr 29, 2017 9:07 am

Just set the default HP of each at your project page.
All future Baddy_Buds spawned will yield the default HP.
Image Image Image
B
31
S
11
G
27
Posts: 748
Reputation: 17,093

Post » Sat Apr 29, 2017 1:50 pm

Solid advice, thanks; I'll implement it right away.

Still, it doesn't answer my question. I'd like to know how to tell whether this statement (and similar) affect one or all instances, and how to make sure I can do whichever I need.
B
10
S
3
Posts: 10
Reputation: 670

Post » Sat Apr 29, 2017 1:55 pm

ImageImageImage
B
71
S
22
G
240
Posts: 3,734
Reputation: 133,994

Post » Sat Apr 29, 2017 2:01 pm

@ShinjiDammit in your example only the Baddy_Bud that is being created will be affected, as it is the only one that is picked.

You use the conditions to select the objects to which you want to apply the following actions. For example:

SpriteA Compare Height > 50: SpriteA Set width to 100

...will pick all spriteA instances with a height greater than 50 and change their width to 100. All SpriteA with their height equal to or less than 50 will be unaffected.

SpriteA Compare Height > 50
>SpriteA Compare value Animal = "chicken": SpriteA Set width to 100

...will first pick all spriteA instances with a height greater than fifty, then from that group all SpriteA whose instance value Animal equals "chicken" and then change their width to 100. All SpriteA with their height equal to or less than 50 or whose Animal is not "chicken" will be unaffected.

You can use nested conditions like this to narrow down the size of the group that will be affected by the actions.

If you refer to an object type in the actions without specifying any conditions that pick instances of that object then all instances of that object will be picked:

SpriteA Compare Height > 50
>SpriteA Compare value Animal = "chicken": SpriteA Set width to 100; SpriteB Set width to 100

...all of SpriteB instances will be affected and have their width set to 100.


Sometimes, after applying lots of selection conditions to narrow down your group of objects, you may want to reselect all members of that object type in a sub-event; in that situation you can use the system condition: "Pick All".
Last edited by mekonbekon on Sat Apr 29, 2017 2:03 pm, edited 3 times in total.
B
20
S
8
G
3
Posts: 457
Reputation: 4,053

Post » Sat Apr 29, 2017 2:02 pm

And read the manual entry @blackhornet linked to! :)
B
20
S
8
G
3
Posts: 457
Reputation: 4,053


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest