how to pass pointers using event functions

Posted By: MPQ

how to pass pointers using event functions - 12/07/10 22:01

Hi everybody,

I have the folloing problem: There is no possiblity to pass pointers, references, parametes unsing the event function.

My objective is the following: removing an Entity (a local one!) when hitting an other entity!

example

Code:
void ent_1(ENTITY* temp)
{
   c_move (temp, ...);
   temp.emask = ENABLE_ENTITY;
   temp.event = remove_temp;//here is the problem: no parameter can be passed
}


void remove_temp (HERE NO PARAMENTER POSSIBLE)
{
   ent_remove (THE temp POINTER is invalid here);
}


Posted By: Superku

Re: how to pass pointers using event functions - 12/07/10 22:23

Code:
void remove_temp()
{
   ent_remove(me);
}
void ent_1(ENTITY* temp)
{
   c_move (temp, ...);
   temp.emask = ENABLE_ENTITY;
   temp.event = remove_temp;//here is the problem: no parameter can be passed
}



Doesn't this work?
Posted By: MPQ

Re: how to pass pointers using event functions - 12/07/10 22:31

ok i ll try out:

ok it looks like that the me pointer is automatically passed, thank you superku. But an other problem arises: When the entity is removed, the local entity of the calling function becomes invalid, what to do laugh

Code:
void remove_temp()
{
   wait(1);
   ent_remove(me);//now the temp pointer of the calling function becomes invalid

}
void ent_1(ENTITY* temp)
{
   temp.emask = ENABLE_ENTITY;
   temp.event = remove_temp;//here is the problem: no parameter can be passed
   while(1)//while(temp)
   {
      c_move (temp, ...);//temp becomes invalid when it is removed, invalid pointer error
      wait(1);
   }

}



no idea?
Posted By: txesmi

Re: how to pass pointers using event functions - 12/09/10 14:32

you can do something like this

Code:
void remove_temp()
{
   my.skill1 = 1;
}
void ent_1(ENTITY* temp)
{
   temp.emask = ENABLE_ENTITY;
   temp.event = remove_temp;

   while(!temp.skill1)
   {
      c_move (temp, ...);
      wait(1);
   }

   ent_remove(temp);
}


Posted By: MPQ

Re: how to pass pointers using event functions - 12/10/10 10:24

thanks i'll try this out
Posted By: MPQ

Re: how to pass pointers using event functions - 12/24/10 10:50

thanx with the pattern of txsmi it works pretty well, the code looks like that:
Code:
int remove_temp()
{
   return (my.skill1 = 1);
}

void ent_move(ENTITY *temp)
{
   temp.emask = ENABLE_ENTITY;
   temp.event = remove_temp;

   while(!temp.skill1)
   {
      c_move (temp, ...);
      wait(1);
   }

   ent_remove(temp);
}

void create_ent()
{
   ENTITY *temp1;
   temp1 = ent_create (...);
   ent_move (temp1);
}



Ok, the handing over of pointers works quite well so far, but why does lite-c not support references, I thought it would be more like C++ and supports this feature, but here it look more like C. Does lite-c support Classes?
© 2024 lite-C Forums