Jump to content


Photo

place_meeting causing crashes


  • Please log in to reply
3 replies to this topic

#1 lightning storm

lightning storm

    GMC Member

  • GMC Member
  • 62 posts

Posted 21 February 2012 - 01:40 PM

All right, so, I'm creating a game, in which the player can attack, which creates a hitbox, which then has each enemy check to see if it intersects with the hitbox. However, for some bizarre reason, whenever the player is facing to the left, and hits an enemy, the game freezes, and I'm forced in to ending the task manually. If I don't hit an enemy, or hit an enemy while facing the right, it works fine. I know the problem is with the line
if Hit <= 0 and place_meeting(x,y,Hitbox)
I've commented out the "place_meeting(x,y,Hitbox)" part before, and it doesn't crash, though it does stop doing what I want it to. So, for some reason, that's causing crashes. Any information or assistance would be great. Here's the relevant code:
(Oh, and yeah, I know it's sloppy, I'm going to tidy it up once this starts working.)
Player Attack Key Event:
if Damaged = false
    {
    Take_Action("PuddingAttack")
    }

Take_Action function
if Attacking = false
{
Attacking = true
CurrentAction = instance_create(x,y,Hitbox)
if argument0 = "PuddingAttack"
    {
    Duration = 10
    Cooldown = 10
    CurrentActionTime = Cooldown
    CurrentAction.Duration = 10
    CurrentAction.Cooldown = 10
    CurrentAction.AttackFrames = ds_grid_create(10,10)
    CurrentAction.AttackFrames[0,0] = x+(Player.Facing*32) //X-Position
    CurrentAction.AttackFrames[0,1] = y //Y-Position
    CurrentAction.AttackFrames[0,2] = Rectangle //Shape
    CurrentAction.AttackFrames[0,3] = 0 //Rotation
    CurrentAction.AttackFrames[0,4] = 0 //Height
    CurrentAction.AttackFrames[0,5] = 0 //Width
    CurrentAction.AttackFrames[0,6] = 10 //Damage
    CurrentAction.AttackFrames[0,10] = "" //Effects
    CurrentAction.AttackFrames[1,0] = x+(Player.Facing*32) //X-Position
    CurrentAction.AttackFrames[1,1] = y //Y-Position
    CurrentAction.AttackFrames[1,2] = Rectangle //Shape
    CurrentAction.AttackFrames[1,3] = 0 //Rotation
    CurrentAction.AttackFrames[1,4] = 0 //Height
    CurrentAction.AttackFrames[1,5] = 0 //Width
    CurrentAction.AttackFrames[1,6] = 10 //Damage
    CurrentAction.AttackFrames[1,10] = "" //Effects
    CurrentAction.AttackFrames[2,0] = x+(Player.Facing*32) //X-Position
    CurrentAction.AttackFrames[2,1] = y //Y-Position
    CurrentAction.AttackFrames[2,2] = Rectangle //Shape
    CurrentAction.AttackFrames[2,3] = 0 //Rotation
    CurrentAction.AttackFrames[2,4] = 32 //Height
    CurrentAction.AttackFrames[2,5] = 32 //Width
    CurrentAction.AttackFrames[2,6] = 10 //Damage
    CurrentAction.AttackFrames[2,10] = "" //Effects
    CurrentAction.AttackFrames[3,0] = x+(Player.Facing*32) //X-Position
    CurrentAction.AttackFrames[3,1] = y //Y-Position
    CurrentAction.AttackFrames[3,2] = Rectangle //Shape
    CurrentAction.AttackFrames[3,3] = 0 //Rotation
    CurrentAction.AttackFrames[3,4] = 32 //Height
    CurrentAction.AttackFrames[3,5] = 32 //Width
    CurrentAction.AttackFrames[3,6] = 10 //Damage
    CurrentAction.AttackFrames[3,10] = "" //Effects
    CurrentAction.AttackFrames[4,0] = x+(Player.Facing*32) //X-Position
    CurrentAction.AttackFrames[4,1] = y //Y-Position
    CurrentAction.AttackFrames[4,2] = Rectangle //Shape
    CurrentAction.AttackFrames[4,3] = 0 //Rotation
    CurrentAction.AttackFrames[4,4] = 32 //Height
    CurrentAction.AttackFrames[4,5] = 32 //Width
    CurrentAction.AttackFrames[4,6] = 10 //Damage
    CurrentAction.AttackFrames[4,10] = "" //Effects
    CurrentAction.AttackFrames[5,0] = x+(Player.Facing*32) //X-Position
    CurrentAction.AttackFrames[5,1] = y //Y-Position
    CurrentAction.AttackFrames[5,2] = Rectangle //Shape
    CurrentAction.AttackFrames[5,3] = 0 //Rotation
    CurrentAction.AttackFrames[5,4] = 32 //Height
    CurrentAction.AttackFrames[5,5] = 32 //Width
    CurrentAction.AttackFrames[5,6] = 10 //Damage
    CurrentAction.AttackFrames[5,10] = "" //Effects
    CurrentAction.AttackFrames[6,0] = x+(Player.Facing*32) //X-Position
    CurrentAction.AttackFrames[6,1] = y //Y-Position
    CurrentAction.AttackFrames[6,2] = Rectangle //Shape
    CurrentAction.AttackFrames[6,3] = 0 //Rotation
    CurrentAction.AttackFrames[6,4] = 32 //Height
    CurrentAction.AttackFrames[6,5] = 32 //Width
    CurrentAction.AttackFrames[6,6] = 10 //Damage
    CurrentAction.AttackFrames[6,10] = "" //Effects
    CurrentAction.AttackFrames[7,0] = x+(Player.Facing*32) //X-Position
    CurrentAction.AttackFrames[7,1] = y //Y-Position
    CurrentAction.AttackFrames[7,2] = Rectangle //Shape
    CurrentAction.AttackFrames[7,3] = 0 //Rotation
    CurrentAction.AttackFrames[7,4] = 0 //Height
    CurrentAction.AttackFrames[7,5] = 0 //Width
    CurrentAction.AttackFrames[7,6] = 10 //Damage
    CurrentAction.AttackFrames[7,10] = "" //Effects
    CurrentAction.AttackFrames[8,0] = x+(Player.Facing*32) //X-Position
    CurrentAction.AttackFrames[8,1] = y //Y-Position
    CurrentAction.AttackFrames[8,2] = Rectangle //Shape
    CurrentAction.AttackFrames[8,3] = 0 //Rotation
    CurrentAction.AttackFrames[8,4] = 0 //Height
    CurrentAction.AttackFrames[8,5] = 0 //Width
    CurrentAction.AttackFrames[8,6] = 10 //Damage
    CurrentAction.AttackFrames[8,10] = "" //Effects
    CurrentAction.AttackFrames[9,0] = x+(Player.Facing*32) //X-Position
    CurrentAction.AttackFrames[9,1] = y //Y-Position
    CurrentAction.AttackFrames[9,2] = Rectangle //Shape
    CurrentAction.AttackFrames[9,3] = 0 //Rotation
    CurrentAction.AttackFrames[9,4] = 0 //Height
    CurrentAction.AttackFrames[9,5] = 0 //Width
    CurrentAction.AttackFrames[9,6] = 10 //Damage
    CurrentAction.AttackFrames[9,10] = "" //Effects
    }

Hitbox Create Event
Frame = 0

Hitbox Step Event:
x = AttackFrames[Frame,0]
y = AttackFrames[Frame,1]
sprite_index = AttackFrames[Frame,2]
image_angle = AttackFrames[Frame,3]
image_xscale = AttackFrames[Frame,4]
image_yscale = AttackFrames[Frame,5]
global.Damage = AttackFrames[Frame,6]
with(Enemy)
        {
        if Hit <= 0 and place_meeting(x,y,Hitbox)
            {
            HP -= global.Damage
            Hit = 5
            }
        }
Frame+=1
if Frame = Duration
    {
    instance_destroy()
    }

Not sure if either of these will matter, but just in case:

Player step event
SlidingRight = false
SlidingLeft = false
JustJump = false
if place_meeting(x,y+1,Block)
    {
    Grav = 0
    Grav_Dir = 0
    }
else
    {
    Grav = 0.5
    Grav_Dir = 0
    if Vspeed > 0 and place_meeting(x+SP,y,Block)
        {
        SlidingRight = true
        Facing = -1
        }
    if Vspeed > 0 and place_meeting(x-SP,y,Block)
        {
        SlidingLeft = true
        Facing = 1
        }
    }
if Vspeed > VS
    {
    Vspeed = VS
    }
if Vspeed > VSW and (SlidingLeft = true or SlidingRight = true)
    {
    Vspeed = VSW
    }
Player_Up()
if HP < 0
    {
    instance_destroy()
    }
Hit -= 1
if Hit > 0
    {
    Damaged = true
    }
if Hit < 0
    {
    Damaged = false
    Hit = 0
    }
if Damaged = false
    {
    Ouch -= 1
    if Ouch < 0
        {
        Ouch = 0
        }
    }
if CurrentActionTime = 0
Attacking = false
if CurrentActionTime < -1
CurrentActionTime = -1
CurrentActionTime -= 1
Move()

Enemy Step Event
if HP < 0
    {
    instance_destroy()
    }
Hit -= 1
if Hit < 0
    {
    Hit = 0
    }
Move()
if place_meeting(x,y+1,Block)
    {
    Grav = 0
    Grav_Dir = 0
    }
else
    {
    Grav = 0.5
    Grav_Dir = 0
    }
if collision_rectangle(x,y,x+sprite_width,y+sprite_height,Player,true,true)
    {
    Target = collision_rectangle(x,y,x+sprite_width,y+sprite_height,Player,true,true)
    if Target.Ouch <= 0
        {
        Target.HP -= 20
        Target.Hit = 5
        Target.Ouch = 50
        }
    }

Thanks in advance for any help.

Edited by lightning storm, 22 February 2012 - 03:52 AM.

  • 0

#2 lightning storm

lightning storm

    GMC Member

  • GMC Member
  • 62 posts

Posted 22 February 2012 - 03:25 AM

OK, after playing around with it some more, apparently in only happens when the Hitbox object's x coordinate is to the right of the Enemy's, which usually only happens when my sprite is facing left, thus the confusion.

So, essentially, given the code above, why is
place_meeting(x,y,Hitbox)
causing the game to crash when the object using it (Enemy) is placed to the left of Hitbox?

I'll do more testing and add any more information I stumble across.

EDIT:

Wait, sorry, minor correction, it only happens when the x AND y coordinate of the Hitbox OVERLAPS with the Enemy's shape. So, if the Enemy is taking up the space of 0,0 to 32,32, if the Hitbox x,y is anywhere in that square, it crashes. If it overlaps the x coordinate while being above or below, or vise versa, everything works fine, and other parts of the Hitbox can overlap just fine, but when the origin of the Hitbox overlaps with Enemy, it crashes.

Also, when I ran this edited version of the Hitbox Step code:

show_message("1")
x = AttackFrames[Frame,0]
y = AttackFrames[Frame,1]
sprite_index = AttackFrames[Frame,2]
image_angle = AttackFrames[Frame,3]
image_xscale = AttackFrames[Frame,4]
image_yscale = AttackFrames[Frame,5]
global.Damage = AttackFrames[Frame,6]
show_message("2")
with(Enemy)
        {
        show_message("3")
        if Hit <= 0 and place_meeting(x,y,Hitbox)
            {
            show_message("4")
            HP -= global.Damage
            Hit = 5
            }
        }
show_message("5")
Frame+=1
if Frame = Duration
    {
    show_message("6")
    instance_destroy()
    }

If it wasn't overlapping and crashing, it would display 1,2,3,3,3,3,3,3,3,3,3,3,3,3,(It would do 3 for each enemy, as it should),4(if it hit),5,6, which is what I expected.

However, when it did overlap and crash, it would display 1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3 forever, obviously stuck in a loop, which I would have to end manually.

Hope this helps fix my problem.

Edited by lightning storm, 22 February 2012 - 03:48 AM.

  • 0

#3 torigara

torigara

    GMC Member

  • GMC Member
  • 6483 posts

Posted 22 February 2012 - 04:20 AM

image_xscale = AttackFrames[Frame,4]
image_yscale = AttackFrames[Frame,5]

Make sure those values aren't 0. It may cause a problem when you try to check a collision with a zero-width sprite.

CurrentAction.AttackFrames[0,4] = 0 //Height
    CurrentAction.AttackFrames[0,5] = 0 //Width

You seem to be mixing up width (for xscale) and height (for yscale), by the way...

And for your instance, the following line is unnecessary at all. You're using AttackFrames as a 2-d array, totally throwing away the grid that is created (leading into memory leak.)

CurrentAction.AttackFrames = ds_grid_create(10,10)


Edited by torigara, 22 February 2012 - 04:29 AM.

  • 0

#4 lightning storm

lightning storm

    GMC Member

  • GMC Member
  • 62 posts

Posted 22 February 2012 - 04:50 AM


image_xscale = AttackFrames[Frame,4]
image_yscale = AttackFrames[Frame,5]

Make sure those values aren't 0. It may cause a problem when you try to check a collision with a zero-width sprite.

CurrentAction.AttackFrames[0,4] = 0 //Height
    CurrentAction.AttackFrames[0,5] = 0 //Width

You seem to be mixing up width (for xscale) and height (for yscale), by the way...

And for your instance, the following line is unnecessary at all. You're using AttackFrames as a 2-d array, totally throwing away the grid that is created (leading into memory leak.)

CurrentAction.AttackFrames = ds_grid_create(10,10)


Ah! That appears to have been the problem. Thank you so much for all of your help.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users