i cannot get my code to work, i followed a tutorial closely then proof read my work. it worked for the teacher but when i tried it my player was stuck, it didn't animate or move. i split the code up into different parts as that is what was in the tutorial.
here is the main bit :
///script_get_input
right_key = keyboard_check(vk_right);
up_key = keyboard_check(vk_up);
left_key = keyboard_check(vk_left)
down_key = keyboard_check(vk_down)
dash_key = keyboard_check_pressed(ord('C'));
attack_key = keyboard_check(ord('X'));
///check for gamepad input
if (gamepad_is_connected(0)) {
right_key = (gamepad_axis_value( 0, gp_axislh)>= .5);
left_key = (gamepad_axis_value( 0, gp_axislh)>= -.5);
up_key = (gamepad_axis_value( 0, gp_axislv)>= -.5);
down_key = (gamepad_axis_value( 0, gp_axislv)>= .5)
}
and that sets the controls while this sets what they do :
///scr_move_state
scr_get_input();
///get the axis
var xaxis = (right_key - left_key);
var yaxis = (down_key - up_key);
///get direction
dir = point_direction(0, 0, xaxis, yaxis);
///get length
if (xaxis == 0 and yaxis = 0) {
len = 0;
} else {
len = spd;
}
///get the hspd and vspd
hspd = lengthdir_x(len, dir);
vspd = lengthdir_y(len, dir);
///move
phy_position_x += hspd;
phy_position_y += vspd;
///control the sprite
image_speed = sign(len)*.2;
if (len == 0) image_index = 0;
///vertical sprites
if (vspd > 0) {
sprite_index = spr_player_down;
} else if (vspd < 0) {
sprite_index = spr_player_up;
}
///horizontal sprites
if (hspd > 0) {
spr_index = spr_player_right;
} else if (hspd < 0) {
sprite_index = spr_player_left;
}
oh and also how the player interacts with the code
///moves the player in the step event
scr_get_input();
script_execute(state);
it looks really complex and i am just a beginner to coding languages. also i heard that game maker has a unique language making it more difficult. any feedback is appreciated!
This is a weird tutorial. Care to share it?
First of all, you're using the
phy_position_*
variables, this requires your object to be a physics one. Is the object a physics object? Is the physiscs world inialized in your room?Your code in general looks fine. Allthough;
script_execute(state);
looks weird. Do you have a script called state? If so, what are those contents, and why not just run it likestate()
?