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

SOLVED local variable "dash" not set before reading it.

K

Kurumiseenpai

Guest
Hi!

i have this error:

local variable dash(100002, -2147483648) not set before reading it.
at gml_Object_oPlayer_Step_0 (line 145) - case 1:


when i try to start this command:, can anyone help me find the error pls?

var dash;
switch (dash)
{
case 1:
if (keyboard_check(vk_space) && (global.stamina > 0) && (keyboard_check(ord("D"))))
{
global.stamina -= 7
walksp = sprintsp;
sprite_index = dashright;
}
break;


case 2:
if (keyboard_check(vk_space) && (global.stamina > 0) && (keyboard_check(ord("A"))))
{
global.stamina -= 7
walksp = sprintsp;
sprite_index = dashright;
image_xscale = -1;
}
break;

case 3:
if (keyboard_check(vk_space) && (global.stamina > 0) && (keyboard_check(ord("W"))))
{
global.stamina -= 7
walksp = sprintsp;
sprite_index = dashup;
}
break;

case 4:
if (keyboard_check(vk_space) && (global.stamina > 0) && (keyboard_check(ord("S"))))
{
global.stamina -= 7
walksp = sprintsp;
sprite_index = dashdown;
}
break;

default:
walksp = 2;
break;
}
 

pipebkOT

Member
put dash=0; in the create event , not "var dash", don't declare variables as "var variablename" unless it's necessary.

and delete the "var dash" in the step event



declare all variables always in the create event, the step event is to modify that variables.
 
Last edited:

Sabnock

Member
Nothing wrong with using Var (local variable) to declare temporary variables that are discarded at the end of the event if the information they hold is no longer needed but if you want information to survive to the next cycle you need to use an instance variable. Also look at global variables bu tonly so you know what they are and how they are used.
Manual for
Variables And Variable Scope


 
Last edited:

Alivesoft

Member
You don't need var dash or the switch statement at all, try this

walksp = 2;

if ((keyboard_check(vk_space) && (global.stamina > 0)))
{
if (keyboard_check(ord("D")))
{
global.stamina -= 7
walksp = sprintsp;
sprite_index = dashright;
}
else if (keyboard_check(ord("A")))
{
global.stamina -= 7
walksp = sprintsp;
sprite_index = dashleft;
image_xscale = -1;
}
else if (keyboard_check(ord("W")))
{
global.stamina -= 7
walksp = sprintsp;
sprite_index = dashup;
}
else if (keyboard_check(ord("S")))
{
global.stamina -= 7
walksp = sprintsp;
sprite_index = dashdown;
}
}
 
Top