• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM move_snap freezing game

K

Kodidro

Guest
Hi all

I'm fairly new to gamemaker and decided to try to make a short puzzle platformer to help expand my knowledge, I guess. Anyways, I'm trying to figure out how to make an object be "carried" by the player when you hold space, so I have it written as:

if(keyboard_check(vk_space))
{
while(distance_to_object(obj_player) < 25)
{
move_snap(obj_player,obj_player+22)
}
}
else
{
if (hsp < 10) vsp += grav;

if(place_meeting(x,y+vsp,obj_wall))
{
while(!place_meeting(x,y+sign(vsp),obj_wall))
{
y+=sign(vsp);
}
}
}

I have the variable for gravity as "grav" set up to apply my own fall speed. My goal is that when the player holds the space bar, the ball floats over the player like it's being "carried", and otherwise it falls to the ground as normal. The problem is that whenever I press space within 25 pixels, the game seems to freeze - I have to close the whole program to let me start up the game again. I assume there's some problematic interaction with my gravity setup though, because even if I take out the "while" bit I still can't get the object to move above the player.

Any suggestions how I could do this differently?
 
M

Misu

Guest
{
move_snap(obj_player,obj_player+22)
}
obj_player is an object index (assuming). move_snap asks for a grid size to reposition drawing object.

Example: move_snap(32,32) this would align your object on the multiple factor of 32 (32, 64, 96, 128...)
 

Roa

Member
Well I'm almost certain is has to do with while(dist<25) being an infinite loop.

That's not exactly how you should be using while().

You could just set the object being carried x/y pair in the end step event( the end step takes place after transformations are realized.)
 
A

Aura

Guest
You're misunderstanding the move_snap() function. Read the Manual entry to see how it works; it requires a cell size, not an illegal position. Either way, you don't need that. All you need to do is use a variable.

Create:

Code:
being_carried = false;
Space Press:

Code:
if (place_meeting(x, y, obj_player)) {
   being_carried = true;
}
Space Released:

Code:
being_carried = false;
Step:

Code:
if (being_carried) {
   x = obj_player.x;
   y = obj_player.y - 25;
}
else {
   //Gravity and things
Hope that helps! ^^
 
Top