Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, SBGuy), 987 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
vec_to_angle and c_scan makes engine freeze #448408
02/03/15 21:40
02/03/15 21:40
Joined: Dec 2009
Posts: 82
D
Denn15 Offline OP
Junior Member
Denn15  Offline OP
Junior Member
D

Joined: Dec 2009
Posts: 82
i have some enemies in a level and for some reason the engine freezes when they are hit by the player characters scancone and stops responding.

the scancone is used for attacks, so when the player attacks, the player entity uses c_scan around it so the enemy can detect if it has been hit. if an enemy is hit they lose health.

sometimes it takes like 10 hits by c_scan, other times it takes like 2 so i tried to find out what caused it and it turns out that if i remove the vec_to_angle from the following code from the enemy entities' action, then the engine wont freeze:

Code:
action enemy()
{
	wait(-1);
	enemycount = enemycount + 1;
	VECTOR diffen;
	ANGLE angleen;
	c_setminmax(me);
	my.health = 2 + random(4);
	vec_set(my.scale_x, vector(1 + random(1), 1 + random(1), 1 + random(1)));
	//attacking();	
	my.group = 3;
	my.pan = random(360);
	my.emask = ENABLE_SCAN;
	my.event = hit_me;
	set(my, SHADOW);
	while(my.health > 0)
	{
		c_ignore(2, 0);
		c_move(me, vector(my.speed * time_step, 0, 0), nullvector, GLIDE);
		if (my.z < - 1024)
		{
			my.health = 0;
		}
		if (my.speed < 0)
		{
			my.speed = my.speed + 5 * time_step;
		}
		if (vec_dist(my.x, player.x) >= 500) if (my.speed > 0)
		{
			my.speed = my.speed - 5 * time_step;
		}
		if(vec_dist(my.x, player.x) < 500)
		{
			c_trace(vector(my.x, my.y, my.z + 20), player.x, IGNORE_ME);
			if(you)
			{
				vec_diff(diffen, player.x, my.x);
	vec_to_angle------>	vec_to_angle(angleen, diffen);            <-----vec_to_angle
				c_ignore(2, 0);
				c_rotate(me, vector(angleen.pan - my.pan, 0, 0), GLIDE);
				if(my.speed < 20)
				{
					my.speed = my.speed + 5 * time_step;
				}
			}
		}
		wait(1);
	}
	combo = combo + 0.1;
	effect(bloodex, 100, my.x, vector(0, 0, 40));
	enemycount = enemycount - 1;
	ent_remove(me);
}



enemies event function:
Code:
function hit_me()
{
	my.health = my.health - 1;
	my.speed = - 20 * player.strength;
	effect(blood, 30, my.x, vector(0, 0, 40));
}


Last edited by Denn15; 02/03/15 21:44.
Re: vec_to_angle and c_scan makes engine freeze [Re: Denn15] #448416
02/04/15 08:29
02/04/15 08:29
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline
Expert
sivan  Offline
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
try to check if (you == player), but preferably use more ignores in c-tracing to not to detect level geometry and other enemies, only the player entity. otherwise the code looks okay for me.


Free world editor for 3D Gamestudio: MapBuilder Editor
Re: vec_to_angle and c_scan makes engine freeze [Re: sivan] #448418
02/04/15 09:45
02/04/15 09:45
Joined: Dec 2009
Posts: 82
D
Denn15 Offline OP
Junior Member
Denn15  Offline OP
Junior Member
D

Joined: Dec 2009
Posts: 82
i tried to check if you was the player entity and made c_trace ignore other entities, but not the ground since i use it to see if the player can be seen be the enemies. however the game still freezes and stops responding.

is there any known typical cause that makes the engine freeze and stop responding that i maybe can look into. the only cuase i know so far is an endless while(1) loop with no wait() in it and i checked that it does not happen anywere

Last edited by Denn15; 02/04/15 09:49.
Re: vec_to_angle and c_scan makes engine freeze [Re: Denn15] #448440
02/05/15 16:44
02/05/15 16:44
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline
Serious User
Reconnoiter  Offline
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
No error message with high warn_level ?

Using pointers & arrays wrong can eventually let to a game crash too (like using an empty pointer in a c_trace etc.), maybe check those.

Also iirc you should not create particles within an entity event function unless you do a wait before that or something like that.

From the manual:
Quote:
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, start particles or change anything else in the level. Thus instructions like c_move, ent_create, ptr_remove, c_trace etc. must not be performed. If the event function must perform such 'critical instructions', precede them by a wait(1) for delaying them to the next frame. Then it's safe.

Re: vec_to_angle and c_scan makes engine freeze [Re: Reconnoiter] #448465
02/05/15 20:20
02/05/15 20:20
Joined: Dec 2009
Posts: 82
D
Denn15 Offline OP
Junior Member
Denn15  Offline OP
Junior Member
D

Joined: Dec 2009
Posts: 82
i have not tried setting a high warn_level but there was 1 single instance where i got a "script crash in enemy" error and the game could continue afterwards and the enemy that crashed did nothing afterwards, however the game froze a little later when hitting another enemy.

i have actually managed to fix the problem by putting a 1 second delay before removing the enemy entity. i guess the problem has something to do with the entity being accessed when its removed or something like that but im still not sure what excactly the problem was.

i also tried removing the effect commands from the events as i read that it was not a good idea in the manual, but it didnt seem to do any difference here.

Re: vec_to_angle and c_scan makes engine freeze [Re: Denn15] #448467
02/05/15 21:17
02/05/15 21:17
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline
Serious User
Reconnoiter  Offline
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
Good to hear that it is solved,

Quote:
i also tried removing the effect commands from the events as i read that it was not a good idea in the manual, but it didnt seem to do any difference here.
, I think that is cause the engine tries to recover from the fault but I don't know for sure (or something maybe with bad memory being written), but I do know you want to prevent it cause when these code bugs do let your game crash their are often alot trickier to track down cause it is not always inmediately clear where they come from.

Last edited by Reconnoiter; 02/05/15 21:18.

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