Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
0 registered members (), 16,302 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
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
A
aaronde Offline OP
Newbie
aaronde  Offline OP
Newbie
A

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.

Code:
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.


Code:
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 Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Code:
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 Offline
Member
tzw  Offline
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 Offline
Expert
EvilSOB  Offline
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: EvilSOB] #358797
02/13/11 13:44
02/13/11 13:44
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Sorry, I can't give you a competent answer, I simply tested it, and this was the way it worked.
I thought to remember that it was sufficient to set "wait(1);" before "ent_remove(me);" instead behind it, but it had no effect.
My experience with Lite-C is more of trial and error, and things that I read in the forums.

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 Offline
Expert
EvilSOB  Offline
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
L
Locoweed Offline
Expert
Locoweed  Offline
Expert
L

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

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1