0 registered members (),
16,302
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
How do I delete an an entity in it's action?
#358741
02/13/11 06:30
02/13/11 06:30
|
Joined: Oct 2010
Posts: 11 Netherlands Antilles
aaronde
OP
Newbie
|
OP
Newbie
Joined: Oct 2010
Posts: 11
Netherlands Antilles
|
I have an entity that I move using c_move and I want it to be removed when it hits with anything. The entity is created in code using this.
wait(-5);
while (1)
{
VECTOR tvec;
ANGLE tang;
vec_set(tang,camera.pan);
tang.pan = camera.pan + random(20) - 10;
vec_for_angle(tvec, tang);
vec_normalize(tvec, 2000);
tvec.z = 600;
vec_add(tvec,camera.x);
ent_create("vogel.mdl",tvec,vogel_action);
wait(random(8)-8.5);
}
Wath it does here is create a new entity each x seconds, relative to the player. This works fine. This is the action.
function vogel_action()
{
my.emask |= ENABLE_SHOOT;
my.event = enemigu_evento;
my.bida = 1;
VECTOR tvec;
ANGLE tang;
while (1)
{
vec_set(tvec,camera.x);
vec_sub(tvec, my.x);
vec_to_angle(tang,tvec);
my.pan = tang.pan;
my.tilt = tang.tilt;
vec_normalize(tvec,time_step * 60);
c_move(my, nullvector,tvec,IGNORE_PASSABLE);
if (HIT_TARGET)
{
ent_remove(my);
}
wait(1);
}
}
Here everything works fine until it collides with something. It gives an E1513 error that I traced to "ent_remove(my);". I read in the manual what the E1513 error is and tried alot of things, but I can't find the error. I tried. Check if (my != NULL) Put a wait(1) before "ent_remove(my);" Use "ptr_remove(my)" Use me instead of my. Putting the c_move statement inside the if clause. And a couple more things I can't remember. If I press cancel on the message box, the game continuous normally.
Last edited by aaronde; 02/13/11 06:34.
|
|
|
Re: How do I delete an an entity in it's action?
[Re: aaronde]
#358747
02/13/11 09:53
02/13/11 09:53
|
Joined: Sep 2003
Posts: 5,900 Bielefeld, Germany
Pappenheimer
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
|
function vogel_action()
{
my.emask |= ENABLE_SHOOT;
my.event = enemigu_evento;
my.bida = 1;
VECTOR tvec;
ANGLE tang;
var ImDead = 0;
while (ImDead == 0)
{
vec_set(tvec,camera.x);
vec_sub(tvec, my.x);
vec_to_angle(tang,tvec);
my.pan = tang.pan;
my.tilt = tang.tilt;
vec_normalize(tvec,time_step * 60);
c_move(my, nullvector,tvec,IGNORE_PASSABLE);
if (HIT_TARGET)
{
ImDead = 1;
}
wait(1);
}
ent_remove(my);
}
|
|
|
Re: How do I delete an an entity in it's action?
[Re: Pappenheimer]
#358749
02/13/11 10:06
02/13/11 10:06
|
Joined: Jan 2011
Posts: 122 GUILIN , CHINA
tzw
Member
|
Member
Joined: Jan 2011
Posts: 122
GUILIN , CHINA
|
because you are in a loop it is mean that you remove the entity.but in next loop the statement still use the "me",but "me" is NULL at all. so it cause the empty pointer.
my upstairs give you a solution A i give you a solution B: if (HIT_TARGET) { ent_remove(my); return; //return NOW!!! }
well, my English is poor .i hope that you can know what i say
Full of my eyes are class struggles.....
|
|
|
Re: How do I delete an an entity in it's action?
[Re: tzw]
#358766
02/13/11 11:37
02/13/11 11:37
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
But Pappenheimer, (beware, I may be about to say something dumb) shouldnt the action self-terminate BECAUSE the me is null?
Seeing as proc_mode=PROC_GLOBAL has NOT been set, dont all actions/functions with that 'me' gert terminated by the engine during the next 'wait phase'?
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: How do I delete an an entity in it's action?
[Re: Pappenheimer]
#358806
02/13/11 15:01
02/13/11 15:01
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Sorry, Pappenhiemer, Im NOT knocking your code!
It looks fine, and its easily understandable, but I dont see how it will help him, if my understanding of the engines auto-terminate is correct.
I suspect there is another function at work here triggering the error, that is remembering this entity in something other than 'me' or 'you'. Without more code I cant be sure.
So ::: If Pappenhiemer's solution doesnt work, then I need more code...
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: How do I delete an an entity in it's action?
[Re: EvilSOB]
#359162
02/15/11 22:51
02/15/11 22:51
|
Joined: Oct 2002
Posts: 2,256 Oz
Locoweed
Expert
|
Expert
Joined: Oct 2002
Posts: 2,256
Oz
|
I always remove entity not inside it's own while-wait(1) loop. Easy to and much safer.
It's usually something like:
while(my.Health > 0) { .. wait(1); }
ent_remove(my);
That is safe way to go.
Professional A8.30 Spoils of War - East Coast Games
|
|
|
|