H
Heat4Life
Guest
So, I created this Script and the code inside of It is:
and after that, I created an another script and the code inside of It is:
and After that I inserted the scr_move_state on the Step event of my Player Object and after that I tested my Game and It gives me this error:
Any help will be greatly appreciated!
Code:
/// scr_get_input
var right_key = keyboard_check(vk_right);
var left_key = keyboard_check(vk_left);
var up_key = keyboard_check(vk_up);
var down_key = keyboard_check(vk_down);
Code:
/// scr_move_state
scr_get_input();
// Get the axis
var xaxis = (right_key - left_key);
var yaxis = (down_key - up_key);
// Get direction
var dir = point_direction(0, 0, xaxis, yaxis);
// Get the 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 = 0.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) {
sprite_index = spr_player_right;
} else if(hspd < 0) {
sprite_index = spr_player_left;
}
Code:
ERROR!!! :: ############################################################################################
FATAL ERROR in
action number 1
of Step Event0
for object obj_player:
Variable obj_player.right_key(100002, -2147483648) not set before reading it.
at gml_Script_scr_move_state (line 6) - var xaxis = (right_key - left_key);
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_scr_move_state (line 6)
called from - gml_Object_obj_player_StepNormalEvent_1 (line 1) - script_execute(state);