• 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!

[Not the real problem so solved I guess] Animate Ability Once

H

Hadin

Guest
So I thought I'd moved past these problems but I guess not and I'm not finding anything online that helps. I added a roll/dodge ability and animation to my character but can't for the life of me figure out how to make it only happen once. I tried all variations of key check pressed and released. Only regular key check plays the animation in full so have stuck with that configuration. Can anyone please help explain how to make events only trigger once each time the correct buttons are pressed.

In the create event of player:

Code:
target_x = mouse_x;
target_y = mouse_y;

In step event:
if(keyboard_check(ord('W')) && keyboard_check(ord('D'))){
    sprite_index = spr_dodge_roll;
    image_speed = .6;
    image_angle = direction;
     if(point_direction(x, y, target_x, target_y) < 20{
             move_towards_point(target_x, target_y, 6);
         }
}
So it's a basic set up to get him to move towards where I want and keep the angle consistent with the direction I'm moving but as long as the buttons are pressed, the animation continuously plays. I've tried putting an animation End with an if statement saying if image index is > 0 and < 4, switch back to walk animation. I've tried using a similar method directly in the step event as well. I just don't understand how it all works together I guess and how and when to tell it to revert back to its walking animation. Please, any help would be greatly appreciated.
 
G

Gillen82

Guest
Try this

Code:
if(keyboard_check(ord('W')) && keyboard_check(ord('D'))){
   sprite_index = spr_dodge_roll;
   image_speed = .6;
   image_angle = direction;

   if ( image_index == image_number -1 ) {

       //Reset back to other sprite index here

   }


    if(point_direction(x, y, target_x, target_y) < 20{
            move_towards_point(target_x, target_y, 6);
        }
}
 
H

Hadin

Guest
Its still the same results. The problem is the key configuration I believe. It is indeed resetting the sprite index back to what it should when I release the buttons so it seems the problem is that it's just continuously playing the animation. So I guess the question now is how to do I limit to ability to only playing once? Using keyboard_check_pressed or released won't play the animation or move the character towards the point. That's why I left it as a normal keyboard_check, its the only one that's even allowing my character to move the way I want him to. Thanks for quick reply.
 
H

Hadin

Guest
After more experimenting I realise its not even doing the move towards point. Its only animating so I really just don't understand how to make this work or get abilities set up properly. I removed the sprite index just to see how it was behaving and it's doing nothing so I need to just figure how to even make the character move how and where before I worry about the animation aspect. So nevermind.
 
G

Gillen82

Guest
@Hadin you're missing a closing parenthesis at the end of you point_direction line of code. Would that be causing an issue?
 
H

Hadin

Guest
Well I typed it out on my tablet and checked for syntax errors first in the program. I don't use my computer for a lot of online business so anytime I type out code for here it's through the tablet. Good catch though.
 
H

Hadin

Guest
Let me just ask this: is there an easy way of knowing how to get something to run a single time or is it always going to have to explicitly be told that after doing x, go back to y or whatever? I ask cause the going back to y part always seems to give me problems, through errors of my own lack of comprehension and whatnot I know but still. Would like to have a better understanding of code structure and know how to see what's wrong with a code I try when it's not working. As is, when I look over the code, from what I understand of it and what I gather from the Game Maker help manual, it should do what I assumed it would.
 
H

Hadin

Guest
Well nevermind. Seems like I've asked too much on here already as I don't really get responses too much. Thanks @Gillen82 for trying to help. I'll just keep using the google route til I find something that works and keep trying to break it all down to understand it.
 
A

Adhiesc

Guest
Hi, I came from seeing your post about "Asking questions not okay". lol. :p
I honestly never noticed this post so I never replied.
Well, I may be able to help a bit? If you want animation to play just once, I'll tell you something about your step event code.
Code:
if(keyboard_check(ord('W')) && keyboard_check(ord('D'))){
   sprite_index = spr_dodge_roll; // # This makes it always play the same sprite, since sprite_index will always be reset to it.
   // bla bla bla
Then, what you need is actually another variable to check if the player 'just-started' to dodge roll. Try this in create event.
Code:
dodge_rolling = false
Then, now, in step event.
Code:
sprite_index = spr_ // Your idle sprite or whatever
// player's state check here
if(keyboard_check_pressed(ord('W')) && keyboard_check_pressed(ord('D')))
{
   // Start dodge rolling
   dodge_rolling = true
}

// Sprite check(s) here (all checks, including sprite, speed, and what the player does when in the mentioned sprite)
if (dodge_rolling)
{
   sprite_index = spr_dodge_roll;
   image_speed = .6;
   if(point_direction(x, y, target_x, target_y) < 20 // I honestly don't know why you add 20 and movement limitations with the mouse here
   {
      move_towards_point(target_x, target_y, 6);
   }
}
// Extra, you can add other ifs if you want.

if (image_index >= image_number)
{
   // Reset dodge roll check
   dodge_rolling = false;
 
   image_index = 0
}

image_angle = direction;
That's all, it may work or not, honestly, depending if the 'point_direction' you used there works, why must it there, you should've knew it for yourself.
 
Last edited by a moderator:
A

Adhiesc

Guest
It's actually not the best code to apply animations and movement there though, unless you have already made the movement code elsewhere.
 
Top