How to use classes in events

I’m trying to make events that will move objects that are part of a class individually. But I’m having problems trying to use commands to effect only one object at a time. I’m trying to simulate having lots of enemies on screen without having to do so much cloning since it’s rough on the performance.

Could somebody give me an explanation on what the commands “All in class…”, “Affected Object from Class…” and “Selected Instance…”. I feel like if I got a better understanding on how these worked I could figure it out. Please help.

1 Like

Make a sprite,
Give a Counter behaviour to the sprite,(set Counter value to 10)(Name HP)
Make a Class (Black) for the sprite,

Make some copies of the sprite,

WHEN all in class Black, Sensing,Touchdown
DO Selected Instance Black,HP,Subtract, 1

This will make only the sprite touched have its Counter lowered by 1
So the Counter will be a value of 9 above the sprite touched

This is probably what you wanted to make individual health points for sprites.

(forgot to mention, the copies Counters only have the same name as the original sprites Counter. The copies Counter value is 0 by default. So you have to manually click each copy and set the counter to 10, or use code blocks and set the Counter to 10 for all in “Black Class”) at the start

For Hiding a copy when it’s counter = 0

WHEN All in class Black,HP, = 0
DO Selected instance Black,Appearance,Set hidden,Yes

1 Like

Yes - this is a good answer, also you can set the parameter values for all objects when the scene starts.

Also:

“Affected” - we use this the method for one or group of objects with the same value. “Selected Instance” - we use when we need to select a specific object or objects with a variety of conditions.

Also, when you use cloning of objects, so that the scene is not overloaded, you can delete them after a certain time.

1 Like