Instances not deleting all the time

Hi all,

I have tried to destroy lasers shot from my ship when outside of the screen by doing this and also setting up laser count to test if it is working correctly with a text displaying the count

When laser is created: +1 to variable lasercount

When out of screen
“Compare X position of object”
Laser > SceneWindowWidth()

  • Delete laser
  • -1 to variable lasercount
    And doing the same for the other quadrants

It works most of the time but every now and then, certain lasercount doesn’t drop.

Any leads? It will be bad if the game is chocked full of unwanted instances. Please advise. Thanks

Several things might cause it. Are there other events that destroy the object? Does it use the “destroy outside screen” behaviour?

Other than that the “only execute once” option can also interfere with your event. If the event has that it wont remove a second laser if it is outside the screen simultaneously. You can also try changing your event to “for every object laser shot repeat”. This will make sure the event is triggered for each laser shot object. And if it still doesn’t work you can also switch to a lifetime system, where each shot gets assigned a lifetime after being created, which is then counted down over time and removes the shot once it reaches zero. I think this would be more economically too, because you don’t have to do all these different position test for each of your shots. But that’s only an option if you don’t absolutely need to destroy shot as soon as they are outside the screen.

I have a delete on collide event. Will check to see if that is the cause.
I’m swapping over from Gamemaker and i keep forgetting there’s the behavior function XD. Thanks i’ll check that out

Thanks, i’ll give that a try

That’s a pretty ingenious way of dealing with it! Thanks

One more question.

I’m trying to use - Count(laser)
For displaying the number of laser objects created by

Modifying Text object: lasercount = “Laser Count:” +Count(laser)

It says invalid syntax. How do i use Count(object) properly?

Count(laser) is a number, you have to convert it into a string:

Do = "Laser Count: " + ToString(Count(laser)) to the text of Lasercount


Hi Lizard-13

That worked perfectly!. Thanks :slight_smile: