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

not set before reading it.

i get the next error:
Variable <unknown_object>.direction(8, -2147483648) not set before reading it.
at gml_GlobalScript_PlayerAnimateSprite (line 2) - var _cardinalDirection = round(direction div 90);

for the next script:

//Update Sprite
var _cardinalDirection = round(direction div 90);
var _totalFrames = sprite_get_number(sprite_index) / 4;
image_index = localFrame + (_cardinalDirection * _totalFrames);
localFrame += sprite_get_speed(sprite_index) / FRAME_RATE;


if (localFrame >= _totalFrames)
{
animationEnd = true;
localFrame -= _totalFrames;
}else animationEnd = false;

someone please help me!
 

Mr Magnus

Viking King
Literally just wrap the entire script in a function, and then call updateSprite() where you need it.
GML:
function updateSprite(){

//Update Sprite
var _cardinalDirection = round(direction div 90);
var _totalFrames = sprite_get_number(sprite_index) / 4;
image_index = localFrame + (_cardinalDirection * _totalFrames);
localFrame += sprite_get_speed(sprite_index) / FRAME_RATE;

if (localFrame >= _totalFrames)
{
   animationEnd = true;
   localFrame -= _totalFrames;
}else animationEnd = false;
}
 
Top