• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML [SEND HELP] Problems in writing code for Button commands and Direction arrays.

Now, I don't notice what is going on with this current code I am writing. The exact process I folloowed while writing this code is this:

-- I create a room, sprite, and an object as a sprite to be used in said room. For the object, I create an event following the following code:

left[0] = vk_left;
right[0] = vk_right;
up[0] = vk_up;
dowm[0] = vk_down;

left[1] = ord("A");
right[1] = ord("D");
up[1] = ord("W");
dowm[1] = ord("S");

spd = 10;

global.SCORE = 0;




-- I then create a step event while creating the following code character-by-character:

for (var i = 0; i < array_length_1d(left); i ++; ) {
if (keyboard_check(left)){
x -= spd;
break;
}
}

for (var i = 0; i < array_length_1d(right); i ++; ) {
if (keyboard_check(right)){
x += spd;
break;
}
}

for (var i = 0; i < array_length_1d(up); i ++; ) {
if (keyboard_check(up)){
y -= spd;
break;
}
}

for (var i = 0; i < array_length_1d(down); i ++; ) {
if (keyboard_check(down)){
y += spd;
break;
}
}


I have no idea what is wrong with this code but whenever I either debug or run the game, this error shows up:

############################################################################################
FATAL ERROR in
action number 1
of Step Event0
for object obj_player:

Variable obj_player.down(100008, -2147483648) not set before reading it.
at gml_Object_obj_player_Step_0 (line 25) - for (var i = 0; i < array_length_1d(down); i ++ ; {
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_obj_player_Step_0 (line 25)


What am I doing wrong?
 
Last edited:

YoSniper

Member
Some of the context in your code is lost because you're not using the [code] and [/code] tags.

For example, the [i] array indices in your code are lost and your text is italicized instead.

Can you edit the post with the code tags?
 

YoSniper

Member
I think your error is hidden behind the fact that the forum text editor interpreted it as smiley faces.

The syntax in a "for" loop is this:

Code:
for(i = 0; i < array_length_1d(left); i++) {
    //do stuff
}
I think you added an extra : or ; after the i++ part, and that's the error.
 

FrostyCat

Redemption Seeker
Please post your code between [code] and [/code] tags. This is important because the sequence [i] appears in your code, and that is the BBCode for italics. Right now we have no way of determining how exactly that's used in your code.

That aside, your problem is these two lines (notice that you did dowm instead of down):
Code:
dowm[0] = vk_down;
Code:
dowm[1] = ord("S");
Whenever you get an unexpected "variable not set" error, one of the first things to check for is typos like this.
 

TheouAegis

Member
You have gravity set somewhere. This apparently is a top-down game, so you have no place for gravity in it. Make sure you don't have gravity set for anything other than 0. thanks
 
Top