Sign in to follow this  

Game Maker v1.3 Code Crashes Game

This topic is 1101 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I was programming a platforming game in Game Maker v1.3 and whenever the player collides with a block the game oddly crashes. I've made sure it didn't just get stuck and become unresponsive by adding an animated sprite in the corner of the screen. The sprite stops moving, and when I exit the game the game window closes by I have to manually stop running the game. This is the code:

///Movement - Player

//Initiate Input
key_right = keyboard_check(vk_right);
key_left = -keyboard_check(vk_left);
key_jump = keyboard_check_pressed(ord('Z'));

//React to Input
dir = key_right + key_left;
hsp = dir * movespeed;
if (vsp < 10) vsp += grav;

if (place_meeting(x, y+1, obj_block)) vsp = key_jump * -jumpspeed;


//Horizontal Collision
if (place_meeting(x + hsp, y, obj_block))
{
    while(!place_meeting(x + sign(hsp), y, obj_block))
    {
        x += sign(hsp);
    }
    hsp = 0;
}
x += hsp;

//Vertical Collision
if (place_meeting(x, y + vsp, obj_block))
{
    while(!place_meeting(x, y + sign(vsp), obj_block))
    {
        y += sign(hsp);
    }
    vsp = 0;
}
y += vsp;

Here's also the code for initiating the variables:

///Initiate Variables - Player
hsp = 0;
vsp = 0;
grav = 0.5;
jumpspeed = 7;
movespeed = 5;
dir = 0;

I'd also like to note that the first code segment is located in the Step event of the "obj_player" object, and the second code segment is located in the Create event of the same object. I hope someone can find the solution to this problem, and I appreciate any help I can get. Thanks!

Share this post


Link to post
Share on other sites

A program becoming unresponsive is quite different to crashing. What you've described sounds more like an infinite loop. From the code snippet you provided, I can see two while loops that - depending on the return value of place_meeting()  - could loop endlessly. I'd start by looking in there.

Share this post


Link to post
Share on other sites

Ryuzaki,

This is what infuriated me most about GameMaker. The same code may work for one person but doesn't work for another. I can see you were following Shaun Spalding's platformer tutorials, which generally the code from that should work. I'm not sure why it's not working for you, it might just be the version of GameMaker? I was running 1.4 until I couldn't stand it anymore and stopped using GameMaker altogether. :P

The while loop should work, even though it seems like it shouldn't. Another reason GameMaker drove me nuts, it encourages bad coding habits!

Anyway, I hope you got it sorted out!

Share this post


Link to post
Share on other sites
//Horizontal Collision
// If our horizontal movement is going to hit an obj_block
if (place_meeting(x + hsp, y, obj_block))
{
    // While moving 1 step at a time will NOT hit an obj_block
    while(!place_meeting(x + sign(hsp), y, obj_block))
    {
        // Move one more step
        x += sign(hsp);
    }

    // stop moving, we hit a wall
    hsp = 0;
}

If for whatever reason, you were moved into a block without pressing left or right (enemy knockback, player teleport, etc) then the while loop would be infinite because sign(0) is 0.

    while(!place_meeting(x + sign(hsp), y, obj_block) 
        && hsp != 0) // If hsp is 0, you're inside a block somehow and need to handle it.
    {
        x += sign(hsp);
    }


@YodamanJer - GameMaker drove me nuts too. It seems like there's no easy way to do things right, and the tool fights you when you try to come up with a clean solution.

Share this post


Link to post
Share on other sites

@YodamanJer - GameMaker drove me nuts too. It seems like there's no easy way to do things right, and the tool fights you when you try to come up with a clean solution.

Yeah, no kidding. I thought it was supposed to be easy, and instead it just made me tear my hair out repeatedly.

If anybody is looking for a good 2D engine, App Game Kit from The Game Creators is pretty good, provided you don't mind programming things from scratch. :) I've been using it for a few days now and it's brilliant. I can program things in there faster and more easily than I ever could with GameMaker!

Another good thing to look into is Stencyl. I tried it for a few days and it was pretty nice!

Share this post


Link to post
Share on other sites

This topic is 1101 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this