Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, 1 invisible), 1,395 guests, and 12 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19055 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 | chip programmers | 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