GameMaker Basic GML, names of build in variables, and How To make some things in GML that I already know how in DnD

Zollock

Member
Hello there I'm just starting with GML so there are many things I don't know, but I suppose it should not be so hard if I already can make many things with DnD
This is are the things I want to know:

.How do reffer to the "key A"? I know that for left or right you use vk_left or right, but if I say vk_a it doesn't work
.Jumping animation with many frames, let's say I have an animation with 9 frames, how do I say "If vspeed is equal than 7 go to image_index 0 with image_speed 0" "If vspeed is equal than 6 go to image_index 1 with image_speed 0" and so on until I have every frame
.Turning animation before flipping the sprite. I have a problem with this one in DnD, when I flip the sprite it doesn't align the way I want, so I manually move it 9 pixels right or left every time it turns, and I feel that could mess up the collision detecting
.Landing animation where you can't move, I think I should make an universal Can't move variable and trigger it during the animation
.Starting to walk animation instead of just playing walk animation
.Not being able to flip the sprite in the air when jumping

If you want to see my code please go to Shaun Spalding platformer tutorial video part 2
Thanks you for your time, and please help
 

rytan451

Member
1.
ord("A")

2.
if (vspeed == 7) {
image_index = 0;
image_speed = 0;
}

3. Consider moving the origin of the sprite.
4. You're on the right track
5. What's the difference?
6. Just run/don't run the sprite flipping code.
 

Nidoking

Member
Have you actually looked at the Manual? At least some of those questions are technically possible to answer with the information given, but there are topics in the Manual that cover all of that.
 

PulseNS

Member
  • Keyboard_check(ord('A')) (check here).
  • Replace N and M here, but basically
    GML:
    if(vspeed == N) {
        image_index = M;
        image_speed = 0;
    }
But check out the "Sprite Properties" section here.
  • This is to do with your sprite origin. It will flip around the point you define, so you will either have to set the origin to the sprite's centre or apply a sprite_offset.
  • You can do that, might be easier using alarms also.
  • You can do a variety of things with the 'starting to walk' animation. For example, setting the sprite index to the starting animation and then switching when the animation ends (image_index == image_number - 1).
  • Just add a check such as if(vspeed > 0) // don't change sprite in your movement code.
There are definitely better ways of doing a lot of this, especially the vspeed and image_index checks, but these are the basics. Honestly the documentation is your best friend for most of these questions.
 

Zollock

Member
1.
ord("A")

2.
if (vspeed == 7) {
image_index = 0;
image_speed = 0;
}

3. Consider moving the origin of the sprite.
4. You're on the right track
5. What's the difference?
6. Just run/don't run the sprite flipping code.
Many Thanks
Let's see
== meant.....A question doesn't it? If vspeed is equal to 7 then image_index etc
So then I copy paste the same for every frame changing the values? How do I say like that "If vspeed is greater than 7 but smaller than 6"?

For 3. Where do I place the change animation action? Like.......... If...... man I'm bad a this...How do I say if you press left key but you are facing right play turning animation, then walking animation?
4. I think this one is easy, so do I go into the movement part of the code and put only execute if "Moving" variable is true? Could you give me a little example of how to do that please? Like do I go to the start of it and say something like if move = 1
{
every line of moving code
}
Like that?
5. I should replace walking animation with starting to walk, don't I? And then go to Animation End event and say: If sprite index = spr_walk start
{
sprite_index = walk
}
But wouldn't that create some problems? Cause Starting to walk my override Walking in code, I should add something like "Do not play Starting to Walk if Walking animation is already playing"

6. I think I can figure out this one

Many thanks again
 

Zollock

Member
1.
ord("A")

2.
if (vspeed == 7) {
image_index = 0;
image_speed = 0;
}

3. Consider moving the origin of the sprite.
4. You're on the right track
5. What's the difference?
6. Just run/don't run the sprite flipping code.
ord("A") doesn't work
I will write down the full thing
It is currently: keyboard_check_pressed(vk_space);
Do I turn it into: "keyboard_check_pressed(ord_a);" ? Cause it isn't red like the others
 

saffeine

Member
Many Thanks
Let's see
== meant.....A question doesn't it? If vspeed is equal to 7 then image_index etc
So then I copy paste the same for every frame changing the values? How do I say like that "If vspeed is greater than 7 but smaller than 6"?

For 3. Where do I place the change animation action? Like.......... If...... man I'm bad a this...How do I say if you press left key but you are facing right play turning animation, then walking animation?
4. I think this one is easy, so do I go into the movement part of the code and put only execute if "Moving" variable is true? Could you give me a little example of how to do that please? Like do I go to the start of it and say something like if move = 1
{
every line of moving code
}
Like that?
5. I should replace walking animation with starting to walk, don't I? And then go to Animation End event and say: If sprite index = spr_walk start
{
sprite_index = walk
}
But wouldn't that create some problems? Cause Starting to walk my override Walking in code, I should add something like "Do not play Starting to Walk if Walking animation is already playing"

6. I think I can figure out this one

Many thanks again
1a. == doesn't mean a question per se, it's a comparison. if is the question. if( variable == 7 ){ /* do something here if the variable is equal to 7 */ }
1b. you have two options here, you can either make a long sequence of if checks and use that, or you can use a switch statement:
GML:
//  IF statement method.
if( vspeed > 5 && vspeed < 6 ){
    /*
        run your code here.
    */
}

if( vspeed > 6 && vspeed < 7 ){
    /*
        run your code here.
        on a side note: a number can't be greater than 7 and less than 6 ;)
    */
}

//  SWITCH statement method. can be done with floor, ceil, or just the raw value.
switch( round( vspeed ) ){
    case 0:
        // if vspeed is larger than -0.5 and smaller than 0.5.
    break;
  
    case 1:
        // if vspeed is larger than 0.5 and smaller than 1.5.
    break;
  
    case 2:
        // if vspeed is larger than 1.5 and smaller than 2.5.
    break;
  
    // etc...
}
3. create a variable in the create event called facing and set it to 1. when the player presses left set it to -1. when the player presses right set it to 1.
once you've set that up, you can just have it check to see what the value of facing is before changing it again, and if it's the opposite, play the animation.

4. that's pretty much it, yeah. if a key is being pressed or a variable equals something, then add the movement speed to the x / y value.

5. you can do all this in code:
GML:
if( moving_right ) {
    if( sprite_index != sprMoveRight ){
        sprite_index = sprMoveRight;
        image_index = 0;
    }
  
    x += 2;
}


ord("A") doesn't work
I will write down the full thing
It is currently: keyboard_check_pressed(vk_space);
Do I turn it into: "keyboard_check_pressed(ord_a);" ? Cause it isn't red like the others
GML:
if( keyboard_check( ord( "A" ) ) ){
 
}
hopefully that covers most, if not all, of the bases.
 
Top