Player Health - Puzzled

Posted By: marxist_reloaded

Player Health - Puzzled - 08/04/06 17:17

When the player's health drops below zero I want to show some splash screens then end the game. I am trying to do this in the main game loop which begins while(1). But when I try to access player health, I get an empty pointer error.

The value I'm using for player health is plBiped01_entity._health__003 This appears to be the correct variable because I use it in a panel in the main function outside of the main game loop, and the correct health is displayed in the panel. But when I do if(plBiped01_entity._health__003 < 0){ do something here} in the main game loop I get an empty pointer error. I am very puzzled. Help appreciated
Posted By: Claus_N

Re: Player Health - Puzzled - 08/04/06 19:27

before using the pointer, check whether it's valid

while(...)
{
...
if(plBiped01_entity != null)
{
Do your stuff
}
...
}
Posted By: marxist_reloaded

Re: Player Health - Puzzled - 08/06/06 03:18

Thanks. Yes, I tried exactly that

Code:
 

if(plBiped01_entity._health__003 != NULL)
{

//do something here with player health plBiped01_entity._health__003

}




The game starts up OK but immediately after loading I still get a W1501 error message saying that plBiped01_entity._health__003 is an empty pointer. If I click OK on the error message the game proceeds perfectly. This doesn't seem logical to me.

Anyhow it got me thinking that the issue only comes up in the first game loop. I added a counter to check for the first game loop and no empty pointer error!

Code:
 
if(loop_count > 1)
{
//do something here with player health plBiped01_entity._health__003

}




And it worked! I'm relieved I've solved the problem but still don't understand why the checking for the NULL pointer didn't work.
Posted By: Claus_N

Re: Player Health - Puzzled - 08/06/06 10:06

Quote:

if(plBiped01_entity._health__003 != NULL)



you are checking whether the SKILL is null (though a skill can't have this value ;P), you need to check whether the ENTITY is null

if(plBiped01_entity != NULL)
Posted By: marxist_reloaded

Re: Player Health - Puzzled - 08/08/06 04:07

Yes, of course! Thanks for that. Works fine now.
© 2024 lite-C Forums