Help with programming

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);
 

ETHC33

Member
im somewhat new to programming too but if something is "not set before reading it" that means there is no number value to the variable. Maybe because it says unknown object that means you haven't called the script to your player correctly, make sure that you have it written in the script or maybe the switch statement or whatever it is is written correctly.
 
im somewhat new to programming too but if something is "not set before reading it" that means there is no number value to the variable. Maybe because it says unknown object that means you haven't called the script to your player correctly, make sure that you have it written in the script or maybe the switch statement or whatever it is is written correctly.
I've tried but everything looks fine, no warnings or anything
 

ETHC33

Member
if you cant solve it instead of deleting it comment it out using //. iv'e made the mistake of deleting before then had to redo the whole tutorial!
 

Khao

Member
If you're using anything newer than 2.3, you need to define functions in your scripts, like this:

GML:
function function_name_here(arguments)
{
    code
}
Then you call the function by using whatever you defined your function as, rather than the name of the script.
 
If you're using anything newer than 2.3, you need to define functions in your scripts, like this:

GML:
function function_name_here(arguments)
{
    code
}
Then you call the function by using whatever you defined your function as, rather than the name of the script.
ohhh
 
If you're using anything newer than 2.3, you need to define functions in your scripts, like this:

GML:
function function_name_here(arguments)
{
    code
}
Then you call the function by using whatever you defined your function as, rather than the name of the script.
wait one more question: the functions are everything that started with "// "correct?
 

NightFrost

Member
wait one more question: the functions are everything that started with "// "correct?
Each singular item that older tutorials called a script, and wanted you to write into a separately created script window, would now be a function. So you would wrap the entire code content with the function definition, and use the name of the script as the name of the function (ie a script called move_state would become a function move_state.)

If you're new to GameMaker I would suggest first taking some GMS2.3-based tutorials so your first experiences are not a process of trying to update older ones to working condition.
 

ETHC33

Member
i've started with shaun spalding's plattform shooter and it's great, from 2017 though.
On udemy slyddar has a dungeon game tutorial that is updated for 2.3 its really good
 
Top