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
1 registered members (Dico), 16,767 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 to use ent_remove() the right way #411381
11/16/12 01:15
11/16/12 01:15
Joined: Dec 2010
Posts: 100
D
Dega Offline OP
Member
Dega  Offline OP
Member
D

Joined: Dec 2010
Posts: 100
Here is my code for a bullet and gun;
Code:
action act_laser()
{
	set(my,PASSABLE);
	my.pan = player.pan;
	var kill_timer = 50;
	while(1)
	{
		c_move(me,vector(50 * time_step,0,0),nullvector,NULL);
		kill_timer -= 1 * time_step;
		if (kill_timer <= 0)
		{
			ent_remove(me);
			return;
		}
		wait(1);
	}
}

action act_lasergun()
{
	set(my,PASSABLE);
	ent_create("models//laserbullet.mdl",vector(my.x,my.y,my.z),act_laser);
	while(1)
	{
		my.pan = player.pan;
		if (!key_j)
		{
			ent_remove(me);
			return;
		}
		wait(1);	
	}
}


I am trying to make it where the gun is created then it creates the bullet right? Then I get an error saying I removed it wrong with error E1516.
How do I properly destroy an object that needs to be used again? or what do I do?


boolean my.awesomeness = so true;
Re: how to use ent_remove() the right way [Re: Dega] #411383
11/16/12 01:51
11/16/12 01:51
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
I somehow doubt your lasergun action is doing what you want it to do. Once it is executed it immedialte creates laser bullet and then waits until the key j is released. Once that has happened it removes itself. That does not sound like a good gun to me... ^^

Nevertheless I don't see why this should throw E1516. Are you sure this is the code responsible for the error? How do you create the lasergun?

Some unrelated remarks about you code:
1. You have to use backslashes in paths, not slashes.
2. You're misusing the while loop concept. In a while loop the condition should determine how long the function runs. But you used an if condition nested in the while loop as a cancellation criterion. Better do it like this:
Code:
while (!key_j)
{
   my->pan = player->pan;
   wait(1);
}
ent_remove(me);


This has similar semantics but is far clearer. For identical semantics use a do while loop instead. The same is true for the action act_laser. The kill_timer var should be in the condition of the while loop.


Always learn from history, to be sure you make the same mistakes again...

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