F
Feast For Worms
Guest
Hello everyone,
I have a coding error that I cannot seem to solve by myself so I hope you can help.
I have a spawn controller object that runs on an alarm event. There is a step event in the object besides the alarm.
While in open areas, the spawn controller works well. However, when entering tighter areas of the levels or the edges of the level, I run into a hard crash.
When running debug, I've diagnosed that my while loop is causing an infinite loop that crashes the game.
I've tried several ways to get around this - disabling/enabling solid objects, trying a do/until loop, if statements, etc - but I'm still having issues...
Here's a snippet of code, highlighted where it's getting caught up.
SPAWNER CODE
...and just a quick glimpse at the collision code for safe measure...
COLLISION CODE
Sometimes it'll get caught at the beginning of the while loop. Other times it'll stall during the coordinates.
I've tried replacing it with an if statement, but this causes enemies to spawn and get stuck inside the wall objects, which is less than ideal. Replacing it with a do/until statement worked (mostly) when the objects were made solid, but I'd much rather not deal with solids.
Any help? Am I missing a simple syntax error? Are there any adjustments you would make to the code?
Is there a simpler, easier, better way to code enemy spawning for a platformer?
Any and all help is greatly appreciated!
I have a coding error that I cannot seem to solve by myself so I hope you can help.
I have a spawn controller object that runs on an alarm event. There is a step event in the object besides the alarm.
While in open areas, the spawn controller works well. However, when entering tighter areas of the levels or the edges of the level, I run into a hard crash.
When running debug, I've diagnosed that my while loop is causing an infinite loop that crashes the game.
I've tried several ways to get around this - disabling/enabling solid objects, trying a do/until loop, if statements, etc - but I'm still having issues...
Here's a snippet of code, highlighted where it's getting caught up.
SPAWNER CODE
Code:
if roll <= 1
{
if (spawn) && instance_exists(par_player)
{
with (instance_create(par_player.x + irandom_range(spawnrangemin, spawnrangemax), par_player.y-2, enemy1)) {
while (place_meeting(x,y,par_wall))
{
x = par_player.x + irandom_range(spawnrangemin, spawnrangemax);
y = par_player.y
}
}
COLLISION CODE
Code:
if (place_meeting(x+hspd,y,par_wall))
{
if(!place_meeting(x+sign(hspd),y,par_wall))
{
x += sign(hspd);
}
hspd = 0;
dir *= -1;
}
x += hspd;
//Vertical Collision
if (place_meeting(x,y+vspd,par_wall))
{
if(!place_meeting(x,y+sign(vspd),par_wall))
{
y += sign(vspd);
}
vspd = 0;
if (fearofheights) && !position_meeting(x+(sprite_width/2)*dir, y+(sprite_height/2)+8, par_wall)
{
dir *= -1;
}
}
y += vspd;
Sometimes it'll get caught at the beginning of the while loop. Other times it'll stall during the coordinates.
I've tried replacing it with an if statement, but this causes enemies to spawn and get stuck inside the wall objects, which is less than ideal. Replacing it with a do/until statement worked (mostly) when the objects were made solid, but I'd much rather not deal with solids.
Any help? Am I missing a simple syntax error? Are there any adjustments you would make to the code?
Is there a simpler, easier, better way to code enemy spawning for a platformer?
Any and all help is greatly appreciated!
Last edited by a moderator: