Pointer valid?

Posted By: Dark_samurai

Pointer valid? - 08/12/08 19:07

Hi!
I have the following code:

Code:
entity* temppointer;

function blabla()
{
   var savepointer;
   savepointer = you;
   you = null;
   while(1)
   {
      temppointer = savepointer;
      if(temppointer == NULL) {return(-1);}
      wait(1);
   }
}


But this function will never return -1 because it never goes into the if, even if the you entity is removed. So how can I check if a pointer is still valid even if the pointer isn't set to null from another function?

Thanks for your help!

Dark_Samurai
Posted By: flits

Re: Pointer valid? - 08/12/08 19:10

why not set temppointe to 0 when its removed?
Posted By: Dark_samurai

Re: Pointer valid? - 08/12/08 19:21

Because temppointer is only used for getting access to skills... of the entity, but the pointer itself is saved in the var. So this is like the variable temp (you can/should only use it one frame long because other functions will also use this).
The only solution I currently can imagin would be to use a global pointer for this, but thats not realy handy because in my chase I would need a lot global pointers...

Dark_Samurai
Posted By: Bot190

Re: Pointer valid? - 08/12/08 21:49

if you want the var savepointer to be updated when "you" changes you have to put it in a loop. right now, it sets savepointer to what ever "you" is. but doesn't change when you set "you" to null.
Posted By: testDummy

Re: Pointer valid? - 08/15/08 03:08

Code:
/************************************
	ef_h
		validated get entity by handle
*************************************/
ENTITY* eh1; // entity for ptr_for_handle validation
function ef_h(_handle) {
	eh1 = NULL;
	if (_handle == 0) {
		return(0);
	} 
	eh1 = ptr_for_handle(_handle);
	if (eh1 == NULL) {
		return(0);
	}
	return(handle(eh1));
} 
define _eTarget, skill22;
//...
my._eTarget = handle(you);
//...later
// ...meanwhile back at the ranch
ef_h(my._eTarget);
if (eh1 != NULL) {
	// go home
}
//...

Indeed, it doesn't apply at all.
Posted By: Dark_samurai

Re: Pointer valid? - 08/15/08 09:56

Ok, thanks for your help!
I solved the problem now!

Dark_Samurai
© 2024 lite-C Forums