Mac OSX [SOLVED] Player Won't Stop Moving

M

myemanisbob

Guest
So I'm trying to code a feature where when the player enters a certain area (represented by an object with a collide event with the player), they'll be able to press a button and "hide". I'll animate the sprite and do the enemy AI later, but right now I'm just trying to make it so that when the player "hides", they can't move until they press the button again. Problem is, the player won't stop moving.

Here are my key inputs
Code:
if (hascontrol)
{
    key_left = keyboard_check(vk_left) ||  keyboard_check(ord("A"));
    key_right = keyboard_check(vk_right) || keyboard_check(ord("D"));
    key_jump = keyboard_check_pressed(vk_space);
    key_attack = keyboard_check_pressed(ord("Z"));
    key_shift = keyboard_check(vk_shift);
    key_leftdirection = keyboard_check_pressed(vk_left) ||  keyboard_check_pressed(ord("A"));
    key_rightdirection = keyboard_check_pressed (vk_right) || keyboard_check_pressed(ord("D"));
    key_hide = keyboard_check(vk_up) || keyboard_check(ord("W"));
}
else
{
    key_right = 0
    key_right = 0
    key_jump = 0
    key_attack = 0
    key_shift = 0
    key_leftdirection = 0
    key_rightdirection = 0
    key_hide = 0
}
The key_hide is the one that is supposed to make the player hide.
Here is what I have for hiding in my Player's step event
Code:
if hide == true
{
    hsp = 0
    vsp = 0
}
And finally here is my collision with obj_player event in the region where they should be able to hide
Code:
while obj_player 
{
    if key_hide
    {
        hide = true
    }   
}
Absolutely nothing is happening. I have nothing to get the player out so he should just stop and be stuck with what I have right now. I have a feeling that "hide" is resetting back to false every frame, but I don't know how or why. Any suggestions?
 
I'm not totally sure, as I prefer to do a little test before posting "solutions", but this may be because you are doing some of it in a collision event (?)

If so: you don't need a while statement, as the code block will activate for as long as the objects are found to be in collision. The "if key_hide" would control hide = true, and the rest would just be automatic. However it wouldn't take care of setting hide to false.

Code:
if key_hide
   {
       hide = true
   }
else
{
hide = false
}
That might fix it, but not 100% sure without testing it. The theory is that the collision event will run that code block for as long as there is contact, elsewhere in the step event you are setting key_hide, and it will eventually determine hide.
 
M

myemanisbob

Guest
I'm not totally sure, as I prefer to do a little test before posting "solutions", but this may be because you are doing some of it in a collision event (?)

If so: you don't need a while statement, as the code block will activate for as long as the objects are found to be in collision. The "if key_hide" would control hide = true, and the rest would just be automatic. However it wouldn't take care of setting hide to false.

Code:
if key_hide
   {
       hide = true
   }
else
{
hide = false
}
That might fix it, but not 100% sure without testing it. The theory is that the collision event will run that code block for as long as there is contact, elsewhere in the step event you are setting key_hide, and it will eventually determine hide.
I had to do "obj_player.key_hide" because without the while statement, the code was looking for key_hide in the shadow. Unfortunately, there was no effect. I'm going to try making the shadow object completely inert and doing all the code in the player and see if that changes anything.

Edit: using place_meeting in the player object instead and cutting all code in the other object worked.
 
Top