what am i doing wrong... (restart)

Blitz3D Forums/Blitz3D Beginners Area/what am i doing wrong... (restart)

Braden(Posted 2009) [#1]
this is the last part to this project and I can't figure out what i'm doing wrong! When I try to make the program restart, It doesn't work, it says that the entity could not be found, but the debugger highlights my entitycollide code... I'm still relativley new to blitz but i didn't think creating a simple restart would be this hard... can anyone check to see what i'm doing wrong? I think the main prolem is in my restart function but i can't figure it out...




Matty(Posted 2009) [#2]
In your restart function all the variable names used to store the entity handles are local variables. You either need to store your entity handle variables in global variables, or a type, or pass the 'camera' and other entity handles into the function as a parameter(s).

Oh and if you use clearworld then there is no need to free the entities as it all gets freed by the clearworld. (Note sounds, images, banks are not freed by a clearworld)


Braden(Posted 2009) [#3]
ok, how would I do that? I experimented with what you said except I still got the same errror code....


Matty(Posted 2009) [#4]
Just had a closer look at your code:

If KeyHit(19) restart <-- when you get to here you free all the entities - and do not reload them back in again

If EntityCollided(camera,type_month) <-- after restarting it gets to here and the camera no longer exists because you've just freed it
PositionEntity camera,0,1000,0


You really should have the restart called outside your main loop.
A simple way of doing this is as follows (really basic) though NOT the best:

declare all entity, texture etc variables as global.
Call an initialise function to create everything.
Call a main function to do your main game loop.
Call an deinitialise function when out of the main loop such that
you can then go back to the initialise function and start over again.


Braden(Posted 2009) [#5]
Ok thanks it worked