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

variable not set?

K

kmce

Guest
I keep getting an error that a variable is not set before reading it, but it is. You can see from the picture the variable changes and from the object info below you can see the variable is set in the create event.

Im not sure if im just being a complete fool and misreading the the error, or what. Could someone maybe have a look, im really confused with it



ERROR:

FATAL ERROR in
action number 1
of Step Eventobj_john_torso_walking
for object obj_HipHop_WG_arms_punching:

Variable obj_HipHop_WG_arms_punching.enemyPunch(100006, -2147483648) not set before reading it.
at gml_Object_obj_HipHop_WG_arms_punching_CollisionEvent_102_1 (line 2) - __b__ = action_if_variable( enemyPunch, 1, 0 );


Object info

Information about object: obj_HipHop_WG_arms_punching
Sprite: spr_HipHop_WG_arms_punching
Solid: true
Visible: true
Depth: -1
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
set variable enemyPunch to 1
Alarm Event for alarm 0:
set variable enemyPunch to 1
Step Event:
execute code:

///Change arm back from Punching to Walking

if distance_to_object (obj_john_torso_walking) >10 && distance_to_object (obj_john_torso_walking) <60

{
instance_change (obj_HipHop_WG_arms_walking,true)
};

execute code:

///Instance destroy

if !instance_exists (obj_HipHop_WG_torso_walking)

instance_destroy();

End Step Event:
execute code:

if instance_exists (obj_HipHop_WG_torso_walking)
{
x = obj_HipHop_WG_torso_walking.x;
y = obj_HipHop_WG_torso_walking.y;
}

Collision Event with object obj_john_torso_walking:
if enemyPunch is equal to 1
set the health relative to -20
set variable enemyPunch to 0
play sound snd_pop_punch; looping: false
set Alarm 0 to 10
 

Attachments

L

Linkruler

Guest
It might be the order of objects. Note that it said the variable wasn't set before reading it. If you place the object that sets the variable higher in the resource tree it may fix the issue
 
K

kmce

Guest
The weird thing is, I have it set up in another object basically the same way and it works fine.

Should it not read the variable that is set in create first, then read what is happening in collision and see it was set in create?

***

This is the same code I am using for another part of the game which is working, so really struggling to understand the problem. The only difference is the variable names

object info

Information about object: obj_HipHop_WG_torso_walking
Sprite: spr_HipHop_WG_torso_walking
Solid: true
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

///image index

image_index=-1

execute code:

///hp

global.hpWG=100;

set variable johnPunch to 1
Alarm Event for alarm 0:
set variable johnPunch to 1
Step Event:
execute code:

///Image speed


image_speed=0.5





execute code:

///Distance to john>60

if distance_to_object(obj_john_torso_walking) > 100

{
instance_change (obj_HipHop_WG_torso_smoking, true)
}

execute code:

///Move towards John

if distance_to_object(obj_john_torso_walking) < 40
{
mp_potential_step (obj_john_torso_walking.x,obj_john_torso_walking.y,1,false) ;

}



execute code:

///facing direction

if instance_exists(obj_john_torso_walking)
{
dir = lengthdir_x(distance_to_point(obj_john_torso_walking.x,obj_john_torso_walking.y),point_direction(x,y,obj_john_torso_walking.x,obj_john_torso_walking.y))
image_xscale = sign(dir)*-1
}

if global.hpWG is less than 1
with a chance of 1 out of 1 do perform the next action
create instance of object obj_1up at position (obj_HipHop_WG_torso_walking.xprevious+20,obj_HipHop_WG_torso_walking.yprevious)
execute code:

///HP destroy

if (global.hpWG <=0) instance_change(obj_pop_death, true);



play sound snd_deathPop; looping: false
set the score relative to 20
Collision Event with object obj_john_frontArm_punch:
if johnPunch is equal to 1
execute code:

global.hpWG-=70

play sound snd_johnPunch; looping: false
set variable johnPunch to 0
set Alarm 0 to 10
Collision Event with object obj_John_backArm_punch:
if johnPunch is equal to 1
execute code:

global.hpWG-=70

play sound snd_johnPunch; looping: false
set variable johnPunch to 0
set Alarm 0 to 10
 

Attachments

Top