Instance ID and Random Range Question


Is there anyway to pick specific instances?

I’m making asteroids create 4 smaller asteroids when destroyed.

However, all instances of asteroids gets deleted when 1 gets destroyed.
Or for instance when multiple instances of enemies are on screen but only one is firing.
Attached is the code for my asteroid problem

Regarding Random function. Eg, i’m trying to do spawn enemies at random from say 40 to scenewidth -40.
Do i do it like this? Random( 40, scenewidth -40)

Any help will be much appreciated. Thanks

Your game deletes all asteroids because the event doesn’t specify which asteroid should be destroyed. “asteroidstate” is a global variable, the condition does not check for a specific asteroid being destroyed. So you need a condition that checks for a specific asteroid instance (for destruction I guess you’d typically do that with checking an asteroid instance’ “health” variable, but it’s up to you how you handle it.

Also deleting “asteroid” first will prevent the following events from knowing it’s X/Y so you’ll want to move the deletion below the stuff that checks for asteroid’s properties.

Unless your scene is positioned at 0,0 you’ll also need to specify an x/y to base the randomization on. So its more like
UpperLeftCornerOfSceneX (that is a value an event can have, under “scene” I think) +Random(sceneWidth)

Hope you get it to work. :slight_smile:

When the laser hits the asteroid, add “delete object asteroid” where you also delete the laser. At that time, one specific instance of asteroid is selected; the one undergoing the collision.

Hi Sleeper_service and Mats,

Thanks guys. That makes lots of sense :slight_smile: