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

Legacy GM Can's set local variables

M

Minconan

Guest
I am still a new,something I still don't know now,
about variables,i think I did everything I can and read
everything I can, but it not works.

report:

---------------------------------------------------------------------------------------------------------------------------------------------------

############################################################################################
FATAL ERROR in
action number 1
of Step Event0
for object obj_GasterBlaster:
Variable obj_GasterBlaster.firecooldown(100161, -2147483648) not set before reading it.
at gml_Object_obj_GasterBlaster_StepNormalEvent_1 (line 1) - firecooldown += -1
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_obj_GasterBlaster_StepNormalEvent_1 (line 1)


------------------------------------------------------------------------------------------------------------------------------------------------

the code of [gml_Object_obj_GasterBlaster_StepNormalEvent_1] :

------------------------------------------------------------------------------------------------------------------------------------------------

var firecooldown
var aim_x
var aim_y
var aimdirection
var movedirection
var destory
var follow_x
var follow_y
var way
firecooldown = 30
aim_x = obj_heartmove.x
aim_y = obj_heartmove.y
aimdirection = obj_GasterBlaster.image_angle
movedirection = obj_GasterBlaster.image_angle
destory = 1
follow_x = obj_GasterBlaster.x
follow_y = obj_GasterBlaster.y+25
way = 0


------------------------------------------------------------------------------------------------------------------------------------------------

and I also trid:

var firecooldown = 30
var aim_x = obj_heartmove.x
var aim_y = obj_heartmove.y
var aimdirection = obj_GasterBlaster.image_angle
var movedirection = obj_GasterBlaster.image_angle
var destory = 1
var follow_x = obj_GasterBlaster.x
var follow_y = obj_GasterBlaster.y+25
var way = 0

------------------------------------------------------------------------------------------------------------------------------------------------

still not working....
is anything get wrong or GMS version?
 

FredFredrickson

Artist, designer, & developer
GMC Elder
When you create the object (in your Create event), use this:

Code:
firecooldown = 0
Then you should be able to change the variable in your Step event.

That error is basically saying that the object doesn't contain this variable yet - which usually means it needs to be added at Create.
 

FrostyCat

Redemption Seeker
You have the wrong idea about what var is for. It isn't the universal way to declare variables, it's a specific way to declare variables that won't last between events or script calls. The Manual entry on variable scope makes that very clear.

When you did this in your Create event:
Code:
firecooldown = 30
That's already enough. This line alone makes an instance variable you can use in later events. Sticking in an extra var on top of that makes a local variable instead, and that loses context as soon as the event is over.
 
M

Minconan

Guest
You have the wrong idea about what var is for. It isn't the universal way to declare variables, it's a specific way to declare variables that won't last between events or script calls. The Manual entry on variable scope makes that very clear.

When you did this in your Create event:
Code:
firecooldown = 30
That's already enough. This line alone makes an instance variable you can use in later events. Sticking in an extra var on top of that makes a local variable instead, and that loses context as soon as the event is over.
thx!
 
Top