Not existing variable "not set before reading"

Wasday

Member
Hello everyone, I'm working on a platformer/fighting game right now and I just followed a tutorial on how to add a grapple. However, now when I run my game and press the button to use this grapple i get this error :

ERROR in
action number 1
of Step Event0
for object obj_Reb:

local variable imageindex(100082) not set before reading it.

at gml_Object_obj_Reb_Step_0 (line 85) - if (place_meeting(x, y + ysp, obj_solid))

The problem is that, it is telling me that the "local variable imageindex" is not set before reading it, but I don't have such a variable in my code !
I've been trying to fix it for an hour now, so if anyone has an idea on how to fix this it would be awesome.

Her is my code, it is set in an object called obj_Reb :

Create Event :
grav = 0.8;
speed_x = 0;
speed_y = 0;
speed_wjump_x = 28;
speed_wjump_y = -15;
jumps = 0;
jumpsmax = 2;
onwall = 0;
onground = false;
grav_wall=0.35;
state = pState.normal
gamepad_set_axis_deadzone(0,0.3);
enum pState
{
normal,
swing
}

Step Event :

var k_left = (gamepad_axis_value(0, gp_axislh) < 0);
var k_right = (gamepad_axis_value(0, gp_axislh) > 0);
var k_jump = gamepad_button_check_pressed(0,gp_face1);
onwall = place_meeting(x + 1, y, obj_wall) - place_meeting(x - 1, y, obj_wall);
onground = place_meeting(x,y-1,obj_solid);
var spd_wanted = 0;

switch (state)
{
case pState.normal:
{
if(k_left)
{
spd_wanted -= 8;
}
if(k_right)
{
spd_wanted += 8;
}

if (onwall != 0) && (!onground) && (k_jump)
{
speed_x = -onwall * speed_wjump_x;
speed_y = speed_wjump_y;
jumps += 1;
}

speed_x += (spd_wanted - speed_x) * 0.095; //Smoothly accelerate / decelerate to the wanted speed.

var xsp = round(speed_x);

var grav_final = grav;
if (onwall != 0) && (speed_y > 0)
{
grav_final = grav_wall;
}
speed_y += grav_final; //Apply gravity

if place_meeting(x, y + 1, obj_solid)
{
jumps = jumpsmax;
}
if(k_jump) && (jumps > 0)
{
speed_y = -20;
jumps -= 1;
}

var ysp = round(speed_y);

if (gamepad_button_check(0, gp_face3))
{
grapplex = obj_hook.x;
grappley = obj_hook.y;
ropex = x;
ropey = y;
ropeAngleVelocity = 0;
ropeAngle = point_direction(grapplex,grappley,x,y);
ropelength = point_distance(grapplex,grappley,x,y);
state = pState.swing;
}

}break;
case pState.swing:
{
var _ropeAngleAcceleration = -0.2 * dcos(ropeAngle);
ropeAngleVelocity += _ropeAngleAcceleration;
ropeAngle += ropeAngleVelocity;
ropeAngleVelocity *= 0.99;

ropex = grapplex + lengthdir_x(ropelength,ropeAngle);
ropey = grappley + lengthdir_y(ropelength,ropeAngle);

speed_x = ropex - x;
speed_y = ropey - y;

if (k_jump)
{
state = pState.normal;
}
}break;
}
//---------------------------------------------------------------------------------------
if (place_meeting(x, y + ysp, obj_solid)) => This is the line 85 from the error
{
while(!place_meeting(x, y + sign(ysp), obj_solid))
{
y += sign(ysp);
}
ysp = 0;
speed_y = 0;
if (state = pState.swing)
{
ropeAngle = point_direction(grapplex,grappley,x,y);
ropeAngleVelocity = 0;
}
}
y += ysp;

if (place_meeting(x + xsp, y, obj_solid))
{
while(!place_meeting(x + sign(xsp), y, obj_solid))
{
x += sign(xsp);
}
xsp = 0;
speed_x = 0;
if (state = pState.swing)
{
ropeAngle = point_direction(grapplex,grappley,x,y);
ropeAngleVelocity = 0;
}
}
x += xsp;


(Sorry if my code is really long and messy, I'm still not a pro in coding)
 

gnysek

Member
One of those objects seems to not have sprite/mask set.

Tip: you can use [code ] [/ code] tag to post code (no spaces inside tag), or press </> button on toolbar when writing post.
 

rytan451

Member
One of those objects seems to not have sprite/mask set.

Tip: you can use [code ] [/ code] tag to post code (no spaces inside tag), or press </> button on toolbar when writing post.
The error is for imageindex, not image_index, though...

Try using [ctrl]+[shift]+[F] to search the entire project for "imageindex".
 

gnysek

Member
The error is for imageindex, not image_index, though...
except this error have some own message with typo, and is similar to message for undefined variables.

So I'm asking again, does both objects have sprites set properly, and they aren't set to -1 somewhere in code?
 

rytan451

Member
Not having a sprite set does not cause image_index to suddenly become undefined, nor does it somehow cause imageindex to be read from. It looks like clearing the cache should fix it (broom icon). If it doesn't, then do a filesystem search for imageindex in the project directory.
 
Top