Legacy GM [SOLVED] Variable defined in other object; error appears that it was not defined before being read

T

thecolorthursday

Guest
I am trying to design a small game about flower breeding. I would have a set of gene variables, unique to each instance of a flower object, that would decide the shape and color of parts of the flower and transfer onto their children (with minor changes).

The gene variables are defined here, in the object flower_init after its creation:
instance_create(64, 64, flower);
lc = 0 //leaf colour
c = lc
l = 0 //leaf - leaves and stem
cc = l
b = 0 //bloom - center of flower
d = lc
bc = 0 //bloom colour
dd = lc
f = 0 //flower - flower petals and stuff
e = lc
fc = 0 //flower colour
ee = lc
instance_create(-5, -5, the_end);
instance_destroy();

Here is the flower object, where the variables are used:
depth = -420;
if lc == 0 {
lcl = $93e30a;
}
if lc == 1 {
lcl = $69e116;
}
if lc == 2 {
lcl = $2ece1b;
}
if lc == 3 {
lcl = $11b032;
}
if lc == 4 {
lcl = $138e4d;
}
if lc == 5 {
lcl = $138e89;
}
if lc == 6 {
lcl = $7c138e;
}
if lc == 7 {
lcl = $e32c1b;
}
if lc == 8 {
lcl = $e3a81b;
}
if lc == 9 {
lcl = $e0e31b;
}
if lc == 10 {
lcl = $b8ba62;
}
if lc == 11 {
lcl = $e0f0e5;
}
if lc == 12 {
lcl = $65786c;
}
if lc == 13 {
lcl = $111512;
}

if l == 0 {
leafshape = leaf0;
}
if l == 1 {
leafshape = leaf1;
}
if l == 2 {
leafshape = leaf2;
}
if l == 3 {
leafshape = leaf3;
}
if l == 4 {
leafshape = leaf4;
}
if l == 5 {
leafshape = leaf5;
}
if l == 6 {
leafshape = leaf6;
}
if l == 7 {
leafshape = leaf7;
}
if l == 8 {
leafshape = leaf8;
}
if l == 9 {
leafshape = leaf9;
}
draw_sprite_ext( leafshape, -1, self.x, self.y, 1, 1, 0, lcl, 1);

This is
 
T

thecolorthursday

Guest
Sorry, the last bit cut out. Here it is:

This is the error message that plays when I try to run the game:

___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Create Event
for object flower:

Variable flower.lc(100002, -2147483648) not set before reading it.
at gml_Object_flower_CreateEvent_1 (line 2) - if lc == 0 {lcl = $93e30a;}
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_flower_CreateEvent_1 (line 2)
called from - gml_Object_flower_init_CreateEvent_1 (line 1) - instance_create(64, 64, flower);
 

FrostyCat

Redemption Seeker
You set up lc as an instance variable in flower_init, not in flower. The created flower instance doesn't have that instance variable, so it gives you an error. Also, functions that draw things only work in the Draw event.

When you create the flower instances, make sure that you're setting up the gene instance variables in the created instances. Here are 2 ways to do it:
Code:
with (instance_create(64, 64, flower)) {
  lc = 0;
  c = lc;
  ...
}
Code:
var inst_flower = instance_create(64, 64, flower);
inst_flower.lc = 0;
inst_flower.c = inst.flower.lc;
...
Then you draw the corresponding sprite and blending in flower's Draw event, not in its Create event.
Code:
draw_sprite_ext(leafshape, -1, x, y, 1, 1, 0, lcl, 1);
Make sure to read up the Manual entries on variable scope and basic events. Given the kind of code you wrote and where you placed them, you seem to have the wrong idea about both of these.
 
T

thecolorthursday

Guest
You set up lc as an instance variable in flower_init, not in flower. The created flower instance doesn't have that instance variable, so it gives you an error. Also, functions that draw things only work in the Draw event.

When you create the flower instances, make sure that you're setting up the gene instance variables in the created instances. Here are 2 ways to do it:
Code:
with (instance_create(64, 64, flower)) {
  lc = 0;
  c = lc;
  ...
}
Code:
var inst_flower = instance_create(64, 64, flower);
inst_flower.lc = 0;
inst_flower.c = inst.flower.lc;
...
Then you draw the corresponding sprite and blending in flower's Draw event, not in its Create event.
Code:
draw_sprite_ext(leafshape, -1, x, y, 1, 1, 0, lcl, 1);
Make sure to read up the Manual entries on variable scope and basic events. Given the kind of code you wrote and where you placed them, you seem to have the wrong idea about both of these.
Thank you very much! Sorry, I'm quite new to Gamemaker.
 
Top