Any command to restart your app

Blitz3D Forums/Blitz3D Beginners Area/Any command to restart your app

D_Town_Tony(Posted 2005) [#1]
Is there any command or method if you want to completely restart a game from the beginning, or is that something that I have to code up?


Matty(Posted 2005) [#2]
Something you have to write code for.


daaan(Posted 2005) [#3]
sure...

put a label at the very beggining of your code.
for instance,
.startigpoint

then just use a function like

Function Restart()

freeentity camera
freeentity light
freeentity etc, etc, etc (free any entities that wont
be cleared by clear world)
clearworld
goto startingpoint

End Function


_PJ_(Posted 2005) [#4]
I think this may cause some problems with globals being set 'outside' tyhe main program etc.


doctorskully(Posted 2005) [#5]
Boy, I've run into this problem too. Tank's idea seems to work okay, but it really is simpler just to use ClearWorld (it SHOULD clear everything out involving entites) and EndGraphics (for everything left over). The main problem with tank's idea is the fact that going to a label in a function won't work unless the label is inside the function. You'd have to do it in your main code, not call a function.

As for Globals, just pre-define variables before the label. Instead of:

.start
Global camera = CreateCamera()
Global light = CreateLight()

Do this:

Global camera,light
.start
camera = CreateCamera()
light = CreateLight()

One other thing you could do is that once you have it compiled into an executable, just do this:

ExecFile "myapp.exe"
End

so it'll just restart the application & close the old one. Note: Before compiling, Include won't work because A. it causes major memory leaks and B. a file can only be included once.

Hope this helps you.


jfk EO-11110(Posted 2005) [#6]
This was in my wishlist too since it would make things much easier. However, now I have a function named "reinit_everyhting()". I was scrolling trough the code on a rainy day and copied every variable etc. to a list that would set them to their initial states. Of course, ClearWorld does wipe out the Graphics for me. Alhtough I don't remember exactly if it frees 3D Sounds as well.


jhocking(Posted 2005) [#7]
I don't think ClearWorld does sounds, but that's just my hazy recollection. And for variables, this is why you should use arrays (or better yet, types) as much as possible: to make it easy to loop through and set everything.


Matty(Posted 2005) [#8]
If you design your code right it shouldn't be too difficult at all to remove all resources.

As an example in most of my games I have something similar to this:

function Deinitialise()
ClearWorld

For mousepointer.cursorobj=Each cursorobj
Delete mousepointer
Next

For bullet.projectileobj=Each projectileobj
Delete bullet
Next
For order.marineorderobj=Each marineorderobj
Delete order
Next
For objective.objectiveobj=Each objectiveobj
Delete objective
Next


For Sound.SoundObj=Each Soundobj
If Sound\SndHandle<>0 And Sound\Category<>MenuMusic Then FreeSound Sound\SndHandle
Next
For Weapon.WeaponObj=Each WeaponObj
Delete Weapon
Next 

For LevelData.LevelDataObj=Each LevelDataObj
Delete LevelData
Next
For Level.LevelObj=Each LevelObj
Delete Level
Next

For Item.ItemObj=Each ItemObj
Delete Item
Next 

For Tex.TexObj=Each TexObj
Delete Tex
Next 

For Particle.ParticleObj=Each ParticleObj
Delete Particle
Next

For Emitter.ParticleEmitterObj=Each ParticleEmitterObj
Delete Emitter
Next 

For Mesh.MeshObj=Each meshObj
Delete Mesh
Next 


For Hud.HudObj=Each HudObj
Delete Hud
Next

For Creature.CreatureObj=Each CreatureObj
Delete Creature
Next  
 

End Function






jfk EO-11110(Posted 2005) [#9]
I just mentioned 3D sounds because when you do a Clearworld, it removes everything that is 3D Stuff, so I guess at least some information of 3D Sounds would be lost as well. But since you can play 3D-Sounds as normal sounds too, maybe they just remain there as Non-3D Sounds.


SoggyP(Posted 2005) [#10]
Greetings Puppies,

@Matty: You might want to try
ClearWorld

Delete Each CursorObj
Delete Each projectileobj
Delete Each marineorderobj
Delete Each objectiveobj

For Sound.SoundObj=Each Soundobj
If Sound\SndHandle<>0 And Sound\Category<>MenuMusic Then FreeSound Sound\SndHandle
Next

Delete Each WeaponObj
Delete Each LevelDataObj
Delete Each LevelObj
Delete Each ItemObj
Delete Each TexObj
Delete Each ParticleObj
Delete Each ParticleEmitterObj
Delete Each meshObj
Delete Each HudObj
Delete Each CreatureObj


Peace,

Jes


Matty(Posted 2005) [#11]
Thanks SoggyP - that is a much better method that I hadn't seen before.


jfk EO-11110(Posted 2005) [#12]
You see, as an oldfashioned coder who never uses types, I don't have to delete them, but simply may recycle Vars and Arrays, by initializing them again :P