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

i cant attack

X

xilian7125

Guest
hello, its me again! i keep having problems. im following shaun spalding's melee tutorial and i cant attack? the game turns on but it wont attack when i press z. and when i turn left it stays facing left, even if i go right.
here is ALL my code for player

create
Code:
hsp = 0;
vsp = 0;
grv = 0.4;
walksp = 8;


state = PLAYERSTATE.FREE
hitbyattack = ds_list_create();

enum PLAYERSTATE
{

    FREE,
    ATTACK_SLASH,
    ATTACK_COMBO

}
step
Code:
//player input (check for correct symbols)
key_left = keyboard_check(vk_left);
key_right = keyboard_check(vk_right);
key_jump = keyboard_check_pressed(vk_up);
key_attack = keyboard_check_pressed(ord("z"))

switch (state)

{
    case PLAYERSTATE.FREE: PlayerState_Free(); break;
    case PLAYERSTATE.ATTACK_SLASH: PlayerState_Attack_Slash(); break;
    case PLAYERSTATE.ATTACK_COMBO: PlayerState_Attack_Combo(); break;


}
playerstate_free
Code:
var move = key_right - key_left;

hsp = move * walksp;

vsp = vsp + grv;

if (place_meeting(x,y+1,grass_obj)) && (key_jump)
{
    vsp = -10;
    
}

//horizontal collision
if (place_meeting(x+hsp,y,grass_obj))
{
while (!place_meeting(x+sign(hsp),y,grass_obj))
{
x = x + sign(hsp);
}
hsp = 0;
}
x = x + hsp;

//vertical collision
if (place_meeting(x,y+vsp,grass_obj))
{
while (!place_meeting(x,y+sign(vsp),grass_obj))
{
y = y + sign(vsp);
}
vsp = 0;
}
y = y + vsp;

//animation
if (!place_meeting(x,y+1,grass_obj))
{
    sprite_index = jumpR;
    image_speed = 0;
    if (sign (vsp) > 0) image_index = 1; else image_index = 0;
}

{
    image_speed = 1;
    if (hsp == 0) and key_right = keyboard_check(vk_right)
    {
        sprite_index = sPlayerR;
    }
    
    if (hsp == 8) and key_right = keyboard_check(vk_right)
    {
        sprite_index = sPlayerWR;
    }
    
    if (hsp == -8) and key_left = keyboard_check(vk_left)
    {
        sprite_index = sPlayerWR;
        image_xscale = sign(hsp)
    }
    
    
}

if (key_attack)
{
    state = PLAYERSTATE.ATTACK_SLASH;
}
playerstate_attack
Code:
hsp = 0;
vsp = 0;

//start of the attack
if (sprite_index != sAttack_slash)
{
    sprite_index = sAttack_slash;
    image_index = 0;
    ds_list_clear(hitbyattack);
    
}

mask_index = sAttack_slashHB;
var hitByAttackNow = ds_list_create();
var hits = instance_place_list(x,y,vanta_portal_obj,hitByAttackNow,false);
if (hits > 0)
{
    for (var i = 0; i < hits; i++)
    {
        var hitID = hitByAttackNow[| i]
        if (ds_list_find_index(hitbyattack,hitID) == -1)
        {
            ds_list_add(hitbyattack,hitID);
            with (hitID)
            {
                EnemyHit(2);
            }   
            
            
        }
    }


}
ds_list_destroy(hitByAttackNow);
mask_index = sPlayerR;
if (animation_end())
{
    sprite_index = sPlayerR;
    state = PLAYERSTATE.FREE;

}
im sorry its a lot i just want yall to have all the info
 

TheouAegis

Member
if (hsp == 0)
and key_left = keyboard_check(vk_left)
if (hsp == 0)
and key_right = keyboard_check(vk_right)
You didn't follow Shaun's tutorial that closely, because I doubt Shaun used code like this. Look at the two conditionals posted here and ask yourself, "What's wrong with these two codes?" The codes work -- that's not the problem -- but they are both wrong nonetheless.


As for why you don't change directions when moving right, look at your code. You never tell it to set image_xscale anywhere except when you are sprinting left.
 
Last edited:

FrostyCat

Redemption Seeker
You didn't follow Shaun's tutorial that closely, because I doubt Shaun used code like this. Look at the two conditionals posted here and ask yourself, "What's wrong with these two codes?" The codes work -- that's not the problem -- but they are both wrong nonetheless.
I don't see how those two lines are wrong, in fact this is one place where I dislike Spalding's original method and prefer the variation.

This is Spalding's original method in a nutshell:
Code:
key_right = keyboard_check(vk_right);
key_left = -keyboard_check(vk_left);
var move = key_right + key_left;
One big issue with this setup is that key_left is no longer usable in a Boolean sense (e.g. if (key_left) is meaningless), yet the variable's name and its similarly named partner suggest that it still is. The original poster is using this variation, which I encourage over the Spalding's original method:
Code:
key_right = keyboard_check(vk_right);
key_left = keyboard_check(vk_left);
var move = key_right - key_left;
Here key_left is usable in a Boolean sense, unlike the original. This better accommodates for future expansion and makes more sense with the rest of the setup.
 

TheouAegis

Member
I don't see how those two lines are wrong, in fact this is one place where I dislike Spalding's original method and prefer the variation.

This is Spalding's original method in a nutshell:
Code:
key_right = keyboard_check(vk_right);
key_left = -keyboard_check(vk_left);
var move = key_right + key_left;
One big issue with this setup is that key_left is no longer usable in a Boolean sense (e.g. if (key_left) is meaningless), yet the variable's name and its similarly named partner suggest that it still is. The original poster is using this variation, which I encourage over the Spalding's original method:
Code:
key_right = keyboard_check(vk_right);
key_left = keyboard_check(vk_left);
var move = key_right - key_left;
Here key_left is usable in a Boolean sense, unlike the original. This better accommodates for future expansion and makes more sense with the rest of the setup.
Oh, i didn't consider needing to copy the whole line. I messed up there. I will edit the other post, but THIS is what I was referring to:

if (hsp == 0) and key_right = keyboard_check(vk_right) { sprite_index = sPlayerR; } if (hsp == 8) and key_right = keyboard_check(vk_right) { sprite_index = sPlayerWR; } if (hsp == -8) and key_left = keyboard_check(vk_left) { sprite_index = sPlayerWR; image_xscale = sign(hsp) }
He is comparing the result of a keyboard check to the same keyboard check. If Shaun seriously did that in his code, I would be flabbergasted.
 
Top