SamtheSoupMan
Member
Hello everyone! I'm kinda new to programming and was following this tutorial:
when I ran into a problem. when I try and run the program I get this error message:
___________________________________________
############################################################################################
ERROR in
action number 1
of Create Event
for object <undefined>:
Variable <unknown_object>.yaxis(100003, -2147483648) not set before reading it.
at gml_GlobalScript_move_state (line 3) - dir = point_direction(0, 0, xaxis, yaxis);
############################################################################################
gml_GlobalScript_move_state (line 3)
I can't see where I deviated from his code and I cant figure out what to do to fix it. Ill paste my scripts and events below:
move_state.gml:
/// move_state
// Get Direction
dir = point_direction(0, 0, xaxis, yaxis);
// Get Length
if (xaxis == 0) && (yaxis == 0) {
len = 0;
} else {
len = spd;
}
// Get the speed variables
hspd = lengthdir_x(len, dir);
vspd = lengthdir_y(len, dir);
// Horizontal Collisions
if (place_meeting(x+hspd, y, obj_wall)) {
while(!place_meeting(x+sign(hspd), y, obj_wall)) {
x += sign(hspd);
}
hspd = 0;
}
x += hspd;
// Vertical Collisions
if (place_meeting(x, y+vspd, obj_wall)) {
while(!place_meeting(x, y+sign(vspd), obj_wall)) {
y += sign(vspd);
}
vspd = 0;
}
y += vspd;
_____________________________________________________________________________
get_input.gml
/// @desc get_input()
rKey = max(keyboard_check(vk_right), keyboard_check(ord("D")), 0);
lKey = max(keyboard_check(vk_left), keyboard_check(ord("A")), 0);
dKey = max(keyboard_check(vk_down), keyboard_check(ord("S")), 0);
uKey = max(keyboard_check(vk_up), keyboard_check(ord("W")), 0);
xaxis = (rKey - lKey);
yaxis = (dKey - uKey);
// Gamepd Input
if (gamepad_is_connected(0)) {
rKey = gamepad_button_check(0, gp_padr);
lKey = gamepad_button_check(0, gp_padl);
dKey = gamepad_button_check(0, gp_padd);
uKey = gamepad_button_check(0, gp_padu);
xaxis = max(gamepad_axis_value(0, gp_axislh),
gamepad_axis_value(0, gp_axisrh), rKey - lKey, 0);
yaxis = max(gamepad_axis_value(0, gp_axislv),
gamepad_axis_value(0, gp_axisrv), dKey - uKey, 0);
}
_____________________________________________________________________________
obj_player -> Create - Initialize:
/// @desc Initialize
spd = 1;
hspd = 0;
vspd = 0;
len = 0;
dir = 0;
state = move_state;
_____________________________________________________________________________
obj_player -> Step - Every Step:
/// @desc Every Step
get_input();
depth = -y;
script_execute(state);
___________________________________________
############################################################################################
ERROR in
action number 1
of Create Event
for object <undefined>:
Variable <unknown_object>.yaxis(100003, -2147483648) not set before reading it.
at gml_GlobalScript_move_state (line 3) - dir = point_direction(0, 0, xaxis, yaxis);
############################################################################################
gml_GlobalScript_move_state (line 3)
I can't see where I deviated from his code and I cant figure out what to do to fix it. Ill paste my scripts and events below:
move_state.gml:
/// move_state
// Get Direction
dir = point_direction(0, 0, xaxis, yaxis);
// Get Length
if (xaxis == 0) && (yaxis == 0) {
len = 0;
} else {
len = spd;
}
// Get the speed variables
hspd = lengthdir_x(len, dir);
vspd = lengthdir_y(len, dir);
// Horizontal Collisions
if (place_meeting(x+hspd, y, obj_wall)) {
while(!place_meeting(x+sign(hspd), y, obj_wall)) {
x += sign(hspd);
}
hspd = 0;
}
x += hspd;
// Vertical Collisions
if (place_meeting(x, y+vspd, obj_wall)) {
while(!place_meeting(x, y+sign(vspd), obj_wall)) {
y += sign(vspd);
}
vspd = 0;
}
y += vspd;
_____________________________________________________________________________
get_input.gml
/// @desc get_input()
rKey = max(keyboard_check(vk_right), keyboard_check(ord("D")), 0);
lKey = max(keyboard_check(vk_left), keyboard_check(ord("A")), 0);
dKey = max(keyboard_check(vk_down), keyboard_check(ord("S")), 0);
uKey = max(keyboard_check(vk_up), keyboard_check(ord("W")), 0);
xaxis = (rKey - lKey);
yaxis = (dKey - uKey);
// Gamepd Input
if (gamepad_is_connected(0)) {
rKey = gamepad_button_check(0, gp_padr);
lKey = gamepad_button_check(0, gp_padl);
dKey = gamepad_button_check(0, gp_padd);
uKey = gamepad_button_check(0, gp_padu);
xaxis = max(gamepad_axis_value(0, gp_axislh),
gamepad_axis_value(0, gp_axisrh), rKey - lKey, 0);
yaxis = max(gamepad_axis_value(0, gp_axislv),
gamepad_axis_value(0, gp_axisrv), dKey - uKey, 0);
}
_____________________________________________________________________________
obj_player -> Create - Initialize:
/// @desc Initialize
spd = 1;
hspd = 0;
vspd = 0;
len = 0;
dir = 0;
state = move_state;
_____________________________________________________________________________
obj_player -> Step - Every Step:
/// @desc Every Step
get_input();
depth = -y;
script_execute(state);