• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

I am getting a programming error message: Variable <unknown_object>.y(1, -2147483648) not set before reading it.

So, i follow a tutorial and i made the script as i saw from the tutorial but i got this message



___________________________________________
############################################################################################
ERROR in
action number 1
of Create Event
for object <undefined>:

Variable <unknown_object>.y(1, -2147483648) not set before reading it.
at gml_GlobalScript_move_state (line 13) - if (place_meeting(x+hspd, y, obj_wall))
############################################################################################
gml_GlobalScript_move_state (line 13)

My code is:

GML:
dir = point_direction(0, 0, xaxis, yaxis);

if (xaxis == 0) && (yaxis == 0)
{
    len = 0
} else {
len = spd;   
}

hspd = lengthdir_x(len, dir);
vspd = lengthdir_y(len, dir);

if (place_meeting(x+hspd, y, obj_wall))
{
while(!place_meeting(x+sign(hspd), y, obj_wall))
{
x += sign(hspd);
}
hspd = 0;
}

x += hspd;

if (place_meeting(x, y+vspd, obj_wall) )
{
while(!place_meeting(x, y+sign(vspd), obj_wall))
{
y += sign(vspd);
}
vspd = 0;
}

y += vspd;
it says it starts at 13 line which it writes "if (place_meeting(x+hspd, y, obj_wall))"

I don't know what's wrong with it...any ideas on what's wrong?
Thanks!
 

FoxyOfJungle

Kazan Games
Variable <unknown_object>.y(1, -2147483648) not set before reading it.
at gml_GlobalScript_move_state (line 13) - if (place_meeting(x+hspd, y, obj_wall))
Are you putting this code in a script? put it in the Step Event of an object.
Where are you putting the code? Show me what's in the Create Event.

Which version of Game Maker Studio do you use?
 
Are you putting this code in a script? put it in the Step Event of an object.
Where are you putting the code? Show me what's in the Create Event.

Which version of Game Maker Studio do you use?
I am using version 2.3

Here is what is in the create event
GML:
spd = 1;
hspd = 0;
vspd = 0;
len = 0;
dir = 0;

state = move_state;
Edit: i put it in the step event of the object player but i still get the same error.
 
Last edited:
Did you remove it from the script? Scripts work differently in GMS 2.3, tutorials made in the "before days" generally will not work properly in 2.3.

Improper script usage generates undefined variable errors
When you say remove it from the script you mean i need to delete the script from the scripts folder and write it to the object?...
yes, i have already done it, i created a create event in the object and then i copy pasted it to the object and then i delete the script from the script folder so now the script is only in the object

btw when you say scripts work differently in 2.3?
if i understand their difference in how they work i may be able to fix it.
 
@RefresherTowel is indicating you need to put the content you wish to call in side a function block
GML:
function move_state() {
    ... // put your code here
}
I did it right now and this is what i am getting:


___________________________________________
############################################################################################
ERROR in
action number 1
of Create Event
for object obj_player:

Variable obj_player.move_state(100023, -2147483648) not set before reading it.
at gml_Object_obj_player_Create_0 (line 7) - state = move_state;
############################################################################################
gml_Object_obj_player_Create_0 (line 7)


and here is the code in my object in the step event:

GML:
/// @description Insert description here
// You can write your code in this editor
get_input();
depth = -y;
script_execute(state);


function move_state() {
dir = point_direction(0, 0, xaxis, yaxis);

if (xaxis == 0) && (yaxis == 0)
{
    len = 0
} else {
len = spd;   
}

hspd = lengthdir_x(len, dir);
vspd = lengthdir_y(len, dir);

if (place_meeting(x+hspd, y, obj_wall))
{
while(!place_meeting(x+sign(hspd), y, obj_wall))
{
x += sign(hspd);
}
hspd = 0;
}

x += hspd;

if (place_meeting(x, y+vspd, obj_wall) )
{
while(!place_meeting(x, y+sign(vspd), obj_wall))
{
y += sign(vspd);
}
vspd = 0;
}

y += vspd;
}
and here is the code i have in the same object but in the create event

Code:
spd = 1;
hspd = 0;
vspd = 0;
len = 0;
dir = 0;

state = move_state;
i can't understand what's wrong with the code.
 

chamaeleon

Member
I did it right now and this is what i am getting:


___________________________________________
############################################################################################
ERROR in
action number 1
of Create Event
for object obj_player:

Variable obj_player.move_state(100023, -2147483648) not set before reading it.
at gml_Object_obj_player_Create_0 (line 7) - state = move_state;
############################################################################################
gml_Object_obj_player_Create_0 (line 7)


and here is the code in my object in the step event:

GML:
/// @description Insert description here
// You can write your code in this editor
get_input();
depth = -y;
script_execute(state);


function move_state() {
dir = point_direction(0, 0, xaxis, yaxis);

if (xaxis == 0) && (yaxis == 0)
{
    len = 0
} else {
len = spd;  
}

hspd = lengthdir_x(len, dir);
vspd = lengthdir_y(len, dir);

if (place_meeting(x+hspd, y, obj_wall))
{
while(!place_meeting(x+sign(hspd), y, obj_wall))
{
x += sign(hspd);
}
hspd = 0;
}

x += hspd;

if (place_meeting(x, y+vspd, obj_wall) )
{
while(!place_meeting(x, y+sign(vspd), obj_wall))
{
y += sign(vspd);
}
vspd = 0;
}

y += vspd;
}
and here is the code i have in the same object but in the create event

Code:
spd = 1;
hspd = 0;
vspd = 0;
len = 0;
dir = 0;

state = move_state;
i can't understand what's wrong with the code.
The move_state function shouldn't be in the step event. It should be in a script (that can be named anything, and can contain multiple functions as your game grows).
 
ok, i put it in a script i made the function and i call it...now it worked but my player doesn't move (but at least it run without errors)

so, i have
in my player object > step

get_input();
move_state();

in my player object > create

spd = 1;
hspd = 0;
vspd = 0;
len = 0;
dir = 0;

while i have in my get_input script

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

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);
}
and finally in my move_state script i have

GML:
function move_state(){
function move_state() {
dir = point_direction(0, 0, xaxis, yaxis);

if (xaxis == 0) && (yaxis == 0)
{
    len = 0
} else {
len = spd;   
}

hspd = lengthdir_x(len, dir);
vspd = lengthdir_y(len, dir);

if (place_meeting(x+hspd, y, obj_wall))
{
while(!place_meeting(x+sign(hspd), y, obj_wall))
{
x += sign(hspd);
}
hspd = 0;
}

x += hspd;

if (place_meeting(x, y+vspd, obj_wall) )
{
while(!place_meeting(x, y+sign(vspd), obj_wall))
{
y += sign(vspd);
}
vspd = 0;
}

y += vspd;
}
}
any ideas why it doesn't move?
 

FoxyOfJungle

Kazan Games

I suppose you're doing an RPG, I took your code and fixed your code, you're welcome.



Edit:
Now just modify it the way you want, it already has the base.
 

I suppose you're doing an RPG, I took your code and fixed your code, you're welcome.



Edit:
Now just modify it the way you want, it already has the base.
Thank you very much Foxy!

btw what was wrong with the code?

if i could have numbered 1-1 so i remember them for the next time that i will start making something with gamemaker studio.
 

Yal

šŸ§ *penguin noises*
GMC Elder
It's a good habit to define functions in create events / script files.


if i could have numbered 1-1 so i remember them for the next time that i will start making something with gamemaker studio.
If you start using Git you don't need to manually number different versions of your project ever again, you have an advanced versioning tool that does it for you. (Also it can be used to back stuff up to the cloud). Might be a bit early for you to mess around with something this powerful (and complicated!), but if you wanna work within professional programming, this is a thing that basically EVERYBODY uses, so learning it early gives you a good head start.
 
Top