deleting types (entity doesnt exist)
Blitz3D Forums/Blitz3D Programming/deleting types (entity doesnt exist)
| ||
For s.ship=Each ship If s\hull=0 FreeEntity s\ship_Handle Delete s EndIf Next Every second I call this function to delete the types of dead ships and to free their entities. I recently re-wrote a large part of my game and there is now an error. for s.ship=each ship moveentity s\ship_handle 0,0,s\speed next The above function causes a (entity does not exist) error. I used to be able to do this with no errors and I cant work out what I changed to make it go wrong. What is the best way of using the debuglog to find out what went wrong? |
| ||
make that functionfor s.ship=each ship debuglog s\ship_handle moveentity s\ship_handle 0,0,s\speed next I bet you will find that it is one of your first or last ships. if not, then somthing really is odd. |
| ||
There is a long list of entity numbers, how do I tell if it is the last ship? The ships are successfully moved at the beginning of the game but as soon as one dies the error happens. |
| ||
It sounds like you are running your two pieces of code in the same loop, like this:For s.ship=Each ship If s\hull=0 FreeEntity s\ship_Handle Delete s EndIf moveentity s\ship_handle 0,0,s\speed nextIf that's the case then it needs to go like this instead:: For s.ship=Each ship If s\hull=0 FreeEntity s\ship_Handle Delete s Else moveentity s\ship_handle 0,0,s\speed EndIf nextIf that's not the problem, then it might be helpful to see a bit more code... |
| ||
I have the 2 operations in different functions. There is too much code to post here so Ill give the best description Update_small_ships() is the function that is called every loop and moves the ships forward Choose_target() Is the function that is called once every second and deletes and frees entities. What I am doing used to work. My ships used to have a lot of different types but on someones advice I put every single ship into the same type and implemented the use of entityname and object() commands to speed up type access. I dont know why the error occurs still. |
| ||
There is a long list of entity numbers, how do I tell if it is the last ship? which ever one is 0. The ships are successfully moved at the beginning of the game but as soon as one dies the error happens. ah. didn't know that. I don't think that that's it, fredborg. It might be, however, wouldn't that be a type does not exist error instead of a entity does not exist? Well, try this: for s.ship=each ship if s\ship_handle then moveentity s\ship_handle 0,0,s\speed next if there's still an error, then that means you're freeing the entity but not the type - somehow :P |
| ||
Its weird because I use the types to count the number of ships and display it on the screen. I started off with 20 ships, it went down to 19 as it should, this means that the type was deleted successfully. I also have a similar error with entitypicking, using the handle() and object() commands. It seems to have an error when I do this: s\bullet_collision=EntityPick (s\ship_Handle,20) hit_ship$=EntityName(s\bullet_collision) If hit_ship>0 shoot(s\bullet_handle,hit_ship,s\colour,10,0) EndIf When I use the handle() and object() commands putting if s\bullet_collision>0 used to work but it always equals something bigger than zero even when it doesnt pick an entity when I use object and handle commands. Doesnt make much sense. |
| ||
I just had a look at the debuglog again and the ship that doesnt exist has a hull of 20 when it should be zero. I dont know whats going on. |