|
|
event_type and passing into functions
#450984
04/26/15 13:55
04/26/15 13:55
|
Joined: Apr 2005
Posts: 1,988 Canadian, Eh
DLively
OP
Serious User
|
OP
Serious User
Joined: Apr 2005
Posts: 1,988
Canadian, Eh
|
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.
|
|
|
Re: event_type and passing into functions
[Re: DLively]
#450985
04/26/15 14:02
04/26/15 14:02
|
Joined: Nov 2007
Posts: 2,568 Germany, BW, Stuttgart
MasterQ32
Expert
|
Expert
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
|
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:
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;
}
|
|
|
Re: event_type and passing into functions
[Re: MasterQ32]
#450987
04/26/15 14:48
04/26/15 14:48
|
Malice
Unregistered
|
Malice
Unregistered
|
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
/*
* 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);
}
}
|
|
|
Re: event_type and passing into functions
[Re: ]
#450988
04/26/15 14:50
04/26/15 14:50
|
Joined: Apr 2005
Posts: 1,988 Canadian, Eh
DLively
OP
Serious User
|
OP
Serious User
Joined: Apr 2005
Posts: 1,988
Canadian, Eh
|
@malice: As I said, Thats merely an example. I would never use such a useless code...  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.
Last edited by DLively; 04/26/15 14:55. Reason: made small addition
|
|
|
|
|
|