Any command to restart your app
Blitz3D Forums/Blitz3D Beginners Area/Any command to restart your app
| ||
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? |
| ||
Something you have to write code for. |
| ||
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 |
| ||
I think this may cause some problems with globals being set 'outside' tyhe main program etc. |
| ||
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. |
| ||
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. |
| ||
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. |
| ||
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 |
| ||
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. |
| ||
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 |
| ||
Thanks SoggyP - that is a much better method that I hadn't seen before. |
| ||
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 |