deleting objects

BlitzPlus Forums/BlitzPlus Beginners Area/deleting objects

El Neil(Posted 2006) [#1]
i'm making a bouncy ball game, with ball objects of type "ball".

at the start of the code, the program gets the number of balls to display from an array. the higher the level number, the more balls.

the balls are drawn all at the same time on every tick during the level. however, as expected, the game starts to slow down at about level 6 (55 or so balls). at the end of each level, i use a for...each loop to delete all of the balls before reinitialising the next lot.

the problem is that when you get "game over" and start again on level 1 with 15 balls, the game runs as slow as level 6 did with 55 balls. The code which deletes all the balls is called at the end of each level, whether you win or lose, so they must be gone.

is it possible that when you delete the instances, the space is still reserved in RAM? if so, how do i overwrite the old locations?

neil


kragoth74(Posted 2006) [#2]
Try this:

delete each ball



Grey Alien(Posted 2006) [#3]
hmm, and you are sure they are deleted on game over as well? I guess if they weren't deleted, you'd see them right? Have you tried without debug mode on to see if it's faster? Also maybe the slowdown isn't due to 55 balls, but something else like making a timer each time and not destroying it. Bascially can you start the game and jump to level 6 straight away and check the speed, if it's fast then you know that something else is building up over the levels to slow the game down.


El Neil(Posted 2006) [#4]
yeah i jumped to level 6 straight away and it was fine, but if you play it through it still slowed.

tried "delete each ball" and it works fine now. well, i got bored watching it after 145 balls and it was still running fast, so should be ok.

darn blitz plus manual...

thanks guys

el neil


Grey Alien(Posted 2006) [#5]
ok glad you solved it, so your deletion code was knackered then.


El Neil(Posted 2006) [#6]
yeah but i did it exactly how it said in the command reference, ie:

for nme.ball = each ball

delete nme

next


but as soon as i changed it to


delete each ball

it worked. frustrating, cos it was an error in the manual (unless the method i originally used was designed to delete objects without freeing up the ram). i dunno.


Grey Alien(Posted 2006) [#7]
that method should have worked too, how strange.