event_type and passing into functions

Posted By: DLively

event_type and passing into functions - 04/26/15 13:55

Code:
function dothis(var passinto){
	if (event_type == EVENT_IMPACT){		
		beep();
                wait(passinto);
	}	
}
action elevator_move(){
	my.emask |= ENABLE_IMPACT;
	my.event = dothis(5);
}



Note: The above is merely an example


I would like to pass some variables into my event functions. Can this be done? when i pass into them right now, the event stops.
Posted By: MasterQ32

Re: event_type and passing into functions - 04/26/15 14:02

No this is not possible. Not directly to be exact.
Event functions get the "my" pointer of the entity which triggered the event.
so to pass your 5 to the event, do this:
Code:
function dothis(var passinto){
	if (event_type == EVENT_IMPACT){		
		beep();
                wait(my.skill80);
	}	
}
action elevator_move(){
	my.emask |= ENABLE_IMPACT;
	my.event = dothis;
	my.skill80 = 5;
}

Posted By: Anonymous

Re: event_type and passing into functions - 04/26/15 14:48

Btw if you are going to do so much waiting you should call out of the even and maybe lock the event.

Orginal Code by Uhrwerk
Code:
/*
 * Stops the entity from receiving events of type e_type
 * until no instances of f are running for that entity.
 *
 * f: The function to be waited for.
 * e_type: The type of events to be disabled.
 */
void event_lock(void* f,fixed e_type)
{
	if (!my)
		return;
	
	my->emask &= ~e_type;
	
	while (proc_status2(f,me) != 0)
		wait(1);
	
	my->emask |= e_type;
}


function this_event()
{
  if(event_type == EVENT_IMPACT)
  {
    beep();
    event_lock(this_event, ENABLE_IMPACT);
    wait(my.skill88); 
  }
}

// OR
function call_out_to_wait(ENTITY* event_ent)
{
 ENTITY ent_event_ent =event_ent;
 wait(my.skill88);
  ...do more stuff....;
}

function this_event()
{
   if(event_type == EVENT_IMPACT);
   {
     beep();
     call_out_to_wait(you); 
   }
}

Posted By: DLively

Re: event_type and passing into functions - 04/26/15 14:50

@malice: As I said, Thats merely an example. I would never use such a useless code... wink Also, thanks for the example.

Thanks MasterQ32. I had known that much. But it would have been cool not to have to use skills to do that.
Posted By: Anonymous

Re: event_type and passing into functions - 04/26/15 15:21

Well egg on my face. blush confused
© 2024 lite-C Forums