Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (Ayumi), 662 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
movement making collisions crash #437943
03/01/14 23:22
03/01/14 23:22
Joined: Dec 2009
Posts: 361
R
rtsgamer706 Offline OP
Senior Member
rtsgamer706  Offline OP
Senior Member
R

Joined: Dec 2009
Posts: 361
Hi, I started programming an enemy into my game. I got it to die when it collides with a laser without any problems. Oddly, once I told the enemy to start moving forwards the game would crash whenever it collided with a laser. No error message or anything, the game just closes.
Here are the actions for the laser and the enemy:
Code:
function delete_anim()
{
	var destroy_percent = 0;
	while (my)
	{
		destroy_percent += 6;
		ent_animate(my,"deleting", destroy_percent, 0);
		
		if (destroy_percent >= 100)
		ent_remove(me);
		wait(1);
	}
}

function delete()
{
	if (event_type == EVENT_IMPACT || event_type == EVENT_ENTITY)
	{
		wait(1);
		ent_remove(you);
		ent_morph(me, "goomba_death.mdl");
		delete_anim();
	}
}

action enemy()
{
	c_setminmax(me);
	my.emask |= (ENABLE_IMPACT | ENABLE_ENTITY);
	my.event = delete;
	var temp;
	var walk_percent;
	while (my)
	{
		vec_set (temp, ship.x);
		vec_sub (temp, my.x);
		vec_to_angle(my.pan, temp);
		my.tilt = 0;
		walk_percent += 2;
		ent_animate(my,"step", walk_percent, ANM_CYCLE);
		c_move (me, vector(15*time_step, 0, 0), nullvector, GLIDE | IGNORE_PASSABLE);
		wait(1);
	}
}

action beam()
{
	c_setminmax(me);
	vec_for_vertex(my.x, ship, 3);
	my.pan = delete_ship.pan;
	var laser_lifetime = 200;
	while (my)
	{
		c_move (me, vector(45*time_step, 0, 0), nullvector, GLIDE | IGNORE_PASSABLE);
		laser_lifetime--;
		if (laser_lifetime <= 0)
		ent_remove(me);
		wait(1);
	}	
}


If I remove the movement command in the enemy it dies fine again. I'm really lost as to why this is
thanks for the help

Re: movement making collisions crash [Re: rtsgamer706] #437945
03/01/14 23:44
03/01/14 23:44
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Originally Posted By: The mighty manual
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, or change anything else in the level. Thus instructions like c_move, ent_create, ent_remove, c_trace etc. must not be performed

http://www.conitec.net/beta/aentity-event.htm


Always learn from history, to be sure you make the same mistakes again...
Re: movement making collisions crash [Re: Uhrwerk] #437946
03/02/14 00:08
03/02/14 00:08
Joined: Dec 2009
Posts: 361
R
rtsgamer706 Offline OP
Senior Member
rtsgamer706  Offline OP
Senior Member
R

Joined: Dec 2009
Posts: 361
So I changed the event so now it's just (health being a skill I define at the top):
Code:
function delete()
{
	if (event_type == EVENT_IMPACT || event_type == EVENT_ENTITY)
	{
		wait(1);
		my.health -= 1;
	}
}


and put the rest of the stuff into the action of the entity, so in the loop I have:
Code:
if (my.health <= 0)
		{
			if (you)
			ent_remove(you);
			ent_morph(me, "death_model.mdl");
			destroy_percent += 10;
			ent_animate(my,"deleting", destroy_percent, 0);

			if (destroy_percent >= 100)
			{
				wait(1);
				if (me)
				ent_remove(me);
			}
			wait(1);
		}


now it finishes the death animation and then exists the game.
Putting the remove(you) command into the event doesn't seem to change anything


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