|
my.event question
#292393
10/02/09 21:35
10/02/09 21:35
|
Joined: Jan 2005
Posts: 267 the Netherlands
Paulo
OP
Member
|
OP
Member
Joined: Jan 2005
Posts: 267
the Netherlands
|
Hi, I've just created a piece of code that works. But the manual says that it's not a good idea. The event function itself should be simple. It normally should only transfer information to the entities' main function - it shouldn't perform instructions that can trigger events itself, displace entities, start particles or change anything else in the level. Thus instructions like c_move, ent_create, ptr_remove, c_trace etc. must not be performed. If the event function must perform such 'critical instructions', precede them by a wait(1) for delaying them to the next frame. Then it's safe. In the event function I'm using a while loop, particles and ptr_remove. My idea is I'm only calling the event function 1 time, and not every frame therefore there shouldn't be any problem, right?? Imo cause I'm setting the passble and the invisible the event function turns into a normal function. But I'm really not sure at all. Could some1 correct me or agree? Code:
function rocket_handle()
{
set(my, PASSABLE | INVISIBLE);
var exposion_time = 0;
while(exposion_time < 5)
{
// call function destroy_rocket each frame, generating 3 particle at the position of the entity (my.x)
effect(destroy_rocket, 3, my.x, nullvector);
exposion_time +=1;
wait(1);
}
ptr_remove(me);
}
function enemy_rocket_movement()
{
my.emask |= (ENABLE_BLOCK | ENABLE_ENTITY); // Makes entity sensitive for block and entity collision
my.event = rocket_handle;
while(1)
{
c_move(my,vector(30*time_step,0,0),nullvector,IGNORE_PASSABLE | GLIDE | IGNORE_FLAG2 | ACTIVATE_PUSH); //moves the rocket
wait(1);
}
}
The more you have.. the more you can lose... Dont tell em all you know.....
|
|
|
Re: my.event question
[Re: Paulo]
#292394
10/02/09 22:09
10/02/09 22:09
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
IMHO, what youve got is safe enough. You have disabled the 'parent' entity from causing any more events, and nothing the event itself does can cause any events. Look safe to me...
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
|