• 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!

Code Error That I Cant Figure Out

C

_ComicalGaming_

Guest
OK, so im watching a tutorial, and I have followed everything exactly. AND his is working fine. But when I do it, I get this:


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


Variable obj_player.down_key(100003, -2147483648) not set before reading it.
at gml_Object_obj_player_StepNormalEvent_1 (line 38) - if (!down_key and !up_key and !left_key and !right_key) {
############################################################################################


And I cant figure out what I did wrong. This is the code its referring to:

if (!down_key and !up_key and !left_key and !right_key) {
image_speed = 0;

}

If you know the problem and how to fix it, PLEASE TELL ME. Thanks in advance!
 

Simon Gust

Member
Do you have a spelling error in the code where you set down_key to keyboard_check() ?
or
does this block of code come before the initialisation of the keys?
 
C

_ComicalGaming_

Guest
Do you have a spelling error in the code where you set down_key to keyboard_check() ?
or
does this block of code come before the initialisation of the keys?
There is no spelling errors, and no. It comes after them...
 

Mike

nobody important
GMC Elder
You've not set the variable yet. I suspect you should set it to false in your create event, then clear it inside that check.
 
The error means what it says. You haven't created / declared the variable "down_key" before you tried to use it.

You should post your whole Step Event so we can see the code before where the error is happening.

There should be some code prior to line 38 that you posted that says something like:

Code:
down_key = keyboard_check(vk_down)
 
C

_ComicalGaming_

Guest
The error means what it says. You haven't created / declared the variable "down_key" before you tried to use it.

You should post your whole Step Event so we can see the code before where the error is happening.

There should be some code prior to line 38 that you posted that says something like:

Code:
down_key = keyboard_check(vk_down)
Here is the whole code:
/// Move The Player In The Step Event

/// Move Right
if (keyboard_check(ord("right_key"))) {
phy_position_x += spd;
sprite_index = spr_player_right
image_speed = .2;
}


/// Move Up
if (keyboard_check(ord("up_key"))) {
phy_position_y -= spd;
sprite_index = spr_player_up
image_speed = .2;
}


/// Move Left
if (keyboard_check(ord("left_key"))) {
phy_position_x -= spd;
sprite_index = spr_player_left
image_speed = .2;

}


/// Move Down
if (keyboard_check(ord("down_key"))) {
phy_position_y += spd;
sprite_index = spr_player_down
image_speed = .2;
}


/// Stop Animation

if (!down_key and !up_key and !left_key and !right_key) {
image_speed = 0;

}
 

NicoFIDI

Member
Code:
var right_key = keyboard_check(ord("right_key"));
var up_key = keyboard_check(ord("up_key"));
var left_key = keyboard_check(ord("left_key"));
var down_key = keyboard_check(ord("down_key"));

/// Move Right
if (right_key) {
phy_position_x += spd;
sprite_index = spr_player_right
image_speed = .2;
}


/// Move Up
if (up_key) {
phy_position_y -= spd;
sprite_index = spr_player_up
image_speed = .2;
}


/// Move Left
if (left_key) {
phy_position_x -= spd;
sprite_index = spr_player_left
image_speed = .2;

}


/// Move Down
if (down_key) {
phy_position_y += spd;
sprite_index = spr_player_down
image_speed = .2;
}


/// Stop Animation

if (!down_key and !up_key and !left_key and !right_key) {
image_speed = 0;

}
 

FrostyCat

Redemption Seeker
I'm sure that nonsense conditions like this didn't come exactly from the tutorial:
Code:
keyboard_check(ord("right_key"))
If you mean the right arrow, this is what it should have been like:
Code:
keyboard_check(vk_right)
Only letter and number keys use ord() for their keycodes. The Manual has a full listing of them and you chose not to read it.
 
Top