-1

I currently have a big question for writing code for button commands and direction arrays. I write code for a horizontal button array that is in the form of something like this:

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

Then I create vertical button arrays where thew upward button array is correct but the downward button array is incorrect while distributing this code:

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

When I try and Run the game, it shows this error:

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

What am I doing wrong?

Rob
  • 4,927
  • 4
  • 26
  • 41
  • 2
    You have one too many semi-colons in your for loop. – john Mar 22 '19 at 23:30
  • 1
    I don't like questions where posted code is 'something like' the real code. It's far too easy for you to edit out the actual mistake when you post an approximation to your real code. – john Mar 22 '19 at 23:33
  • 2
    @john GameMaker permits a trailing semicolon in for-loops. As to what does this have to do with C++ tag, a secret to everyone – YellowAfterlife Mar 27 '19 at 05:03

1 Answers1

0

Check where you have defined you down variable and see what's different about it compared with the left variable.

The error shows that the down is not yet defined by the time it's about to use it.

Steven
  • 1,996
  • 3
  • 22
  • 33