Naphier if you already wrote it so write it right
Idea by Naphier:
function DeleteAllContent()
for i = 1 to 1000000
if GetSpriteExists(i) = 1 then DeleteSprite(i) // this is ok aslong theres not Physics Attached to it , cause first you will have to delete the sprite's physics .
if GetObjectExists(i)= 1 then DeleteObject(i) //
if GetImageExists(i)= 1 then DeleteImage(i) // images comes after sprites and objects this order will keep AGK running good while not try to change sprites or objects images as they are deleted. so first the Enteties and then their textures.
if GetMemblockExsists(i) = 1 then DeleteMemblock(i)
if GetSoundExists(i) = 1 then DeleteSound(i)
if GetMusicExists(i) = 1 then DeleteMusic(i)
if i < 13 then if GetVirutalButtonExists(i)= 1 then DeleteVirtualButton(i)
if GetVirtualJoysticExists(i) = 1 then DeleteVirtualJoystick(i)
if GetTextExists(i) =1 then DeleteText(i)
if GetEditBoxExists(i) =1 then DeleteEditBox(i)
if GetParticlesExist(i) = 1 then DeleteParticles(i)
next i
endfunction
so actually if you dont use particles or editboxes or anything else you need to comment them out with "rem" or "//"
in case of 2d physics..
if you want to use this method you will need to use a simple Type
like
type phySprite
Id as integer // the sprite Id
on as integer // Physics on or off
endtype
global AmountOfPhySprites as integer
global dim pS[AmountofPhySprites ] as phySprite
// how many phySprites are you gonna use.. since in the delete loop if you'll go outof bounds the app will crush.
then in the delete function
// add this inside the delete loop
if i < AmountOfPhySprites+1 // adding one is faster on the cpu instead of asking "if i <= AmountofPhySprites" which asks 2 question rather then one,is is smaller, is it equal , you can also "inc" AmountofPhySprites before the deleteloop but dont forget to "dec" it if you are going to use the app again after the deleteAll function
if pS[i].on = 1
SetSpritePhysicsDelete(pS[i].id)
pS[i].on = 0 // you dont really need this if you gonna quit the app but for later use after deleting you should reset this var.
// btw do not delete sprites here as it is meaningless as the function's loop delete them all.
endif
endif
copy pasted the code so ppl wont confuse with the order of things, deleting physics first before anything else.
// app init
type phySprite
Id as integer // the sprite Id
on as integer // Physics on or off
endtype
global AmountOfPhySprites as integer
global dim pS[AmountofPhySprites ] as phySprite
//...
//...
//...
function DeleteAllContent()
for i = 1 to 1000000
// add this inside the delete loop
if i < AmountOfPhySprites+1
if pS[i].on = 1
SetSpritePhysicsDelete(pS[i].id)
pS[i].on = 0
endif
endif
if GetSpriteExists(i) = 1 then DeleteSprite(i) // this is ok aslong theres not Physics Attached to it , cause first you will have to delete the sprite's physics .
if GetObjectExists(i)= 1 then DeleteObject(i) //
if GetImageExists(i)= 1 then DeleteImage(i) // images comes after sprites and objects this order will keep AGK running good while not try to change sprites or objects images as they are deleted. so first the Enteties and then their textures.
if GetMemblockExsists(i) = 1 then DeleteMemblock(i)
if GetSoundExists(i) = 1 then DeleteSound(i)
if GetMusicExists(i) = 1 then DeleteMusic(i)
if i < 13 then if GetVirutalButtonExists(i)= 1 then DeleteVirtualButton(i)
if GetVirtualJoysticExists(i) = 1 then DeleteVirtualJoystick(i)
if GetTextExists(i) =1 then DeleteText(i)
if GetEditBoxExists(i) =1 then DeleteEditBox(i)
if GetParticlesExist(i) = 1 then DeleteParticles(i)
next i
endfunction