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

SOLVED Problem with unknow variable

D

Dwestern

Guest
I've a object o_enemy and in create event i wrote this

Code:
type = 0;

hp = grid_type.typegr [# 0, type];
mov = grid_type.typegr [# 0, type];
dmg = grid_type.typegr [# 0, type];
in create event of object grid_type i wrote this

Code:
typegr = ds_grid_create(3,2);

// type 1
typegr [# 0,0] = 3; // hp
typegr [# 1,0] = 2; // mov
typegr [# 2,0] = 1; // dmg

// type 2
typegr [# 0,1] = 1;
typegr [# 1,1] = 4;
typegr [# 2,1] = 1;
when i run the game, i have this error:

############################################################################################
ERROR in
action number 1
of Create Event
for object o_enemy:

Variable grid_type.<unknown variable>(100013, -2147483648) not set before reading it.
at gml_Object_o_enemy_Create_0 (line 3) - hp = grid_type.typegr [# 0, type];
############################################################################################
gml_Object_o_enemy_Create_0 (line 3)


What's wrong?
In the room there are both of object (grid_type before o_enemy)

Someone can help me?
I use GMS 2.3+

Thank you!
 

Attachments

DaveInDev

Member
are you sure that both objects are created in good order, and that o_enemy is not created before grid_type ?
Maybe check room instance order, or your code if you create them dynamically.
 
D

Dwestern

Guest
I did a test. If I recall a variable that already exists in a previously created object, it works. If I write a variable in a new or old object and recall it, it doesn't work and gives the error "unknown variable"
It's like it won't let me add any new variables...
 

DaveInDev

Member
BTW if I undestand your code, it should be
GML:
hp = grid_type.typegr [# 0, type];
mov = grid_type.typegr [# 1, type];
dmg = grid_type.typegr [# 2, type];
but it's not the problem...
 

TsukaYuriko

☄️
Forum Staff
Moderator
Try to clear your asset cache. That's the brush button next to the run button, or Ctrl+F7.
 
D

Dwestern

Guest
BTW if I undestand your code, it should be
GML:
hp = grid_type.typegr [# 0, type];
mov = grid_type.typegr [# 1, type];
dmg = grid_type.typegr [# 2, type];
but it's not the problem...
Yes, I rewrite the code after an attempt and I make this error.
Thank you for reporting
 
D

Dwestern

Guest
could you show me a screencopy of your room instance order ?
sure you did not confound with the instances layer property list which are very similar ? I did this error several times
Problem resolved, I confused the two lists!
I was really silly!

Thank you very much @DaveInDev!
 
Top