Variable not set before reading it error.

philjay

Member
Hello, im new to the forums, just downloaded gamemaker. I'm having this error message while trying to make animated character movement:

___________________________________________
############################################################################################
ERROR in
action number 1
of Step Event0
for object oPlayer:

Variable oPlayer.localFrame(100009, -2147483648) not set before reading it.
at gml_Script_AnimateSprite (line 5) - image_index = localFrame + (_cDirection * _totalFrames);
############################################################################################
gml_Script_AnimateSprite (line 5)
gml_Object_oPlayer_Step_0 (line 38)



Script: (root)
1.
###
//// update-sprite
function AnimateSprite(){
var _cDirection = round(direction/90);
var _totalFrames = sprite_get_number(sprite_index) / 4;
image_index = localFrame + (_cDirection * _totalFrames);
localFrame += sprite_get_speed(sprite_index) / FRAME_RATE;

//// animation-loop
if (localframe >= _totalFrames)
{
animationEnd = true;
localframe -= _totalFrames;
}else animationEnd = false;
}
###
2. (Step)

###

//// basic-input-commands
keyLeft = keyboard_check(vk_left);
keyRight = keyboard_check(vk_right);
keyUp = keyboard_check(vk_up);
keyDown = keyboard_check(vk_down);

//// other-commands

//// keyActivate = keyboard_check_pressed(vk_space);
//// keyAttack = keyboard_check_pressed(ord("C"));
//// keyItem = keyboard_check_pressed(ord("V"));

//// vector-45-degrees-direction-movement-speed-reduction
//// 0-degrees = Right //// 270-degrees = Down

inputDirection = point_direction(0,0,keyRight-keyLeft,keyDown-keyUp);
inputMagnitude = (keyRight - keyLeft != 0) || (keyDown - keyUp != 0);

//// Player-Movement

hSpeed = lengthdir_x(inputMagnitude * speedWalk, inputDirection);
vSpeed = lengthdir_y(inputMagnitude * speedWalk, inputDirection);

x += hSpeed;
y += vSpeed;

//// Sprite-Update

var _oldSprite = sprite_index;
if (inputMagnitude != 0)
{
direction = inputDirection
sprite_index = spriteRun;
} else sprite_index = spriteIdle;
if (_oldSprite != sprite_index) localFrame = 0;

//// update-image-index
script_execute(AnimateSprite);
###


3. Create
###
/// player move action
image_speed = 0;
hSpeed = 0;
vSpeed = 0;
speedWalk = 3.0;

spriteRun = oPlayerWalk;
spriteIdle = oPlayerSprite;
localframe = 0;
###
 

samspade

Member
It means, as you might now, that you are trying to reference a variable before setting it. You do appear to set the variable localframe in the create event of some object. However, if you look carefully, you will see that your capitalization doesn't match. As you (again probably know) variables are case sensitive.
 

philjay

Member
Fixed... I'm sorry for all the trouble only by not capitalizing a variable... problem is fixed. and all script credits are to Shaun Spaulding for the RPG tutorial I'm following.
Thanks guys
 
Top