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

Help with instance.

Hello, I would like some help. Basically what I am trying to do is breed slimes but the issue is that the child is not breeding with the parent.

o_slime1 and o_slime2 is clicked and then o_breed_button is clicked, then o_s_child1 is spawned.
Now I want to click o_s_child1 and then either o_slime1/o_slime2 and then breed another slime.
This works with the first instance of o_s_child1 created.

The problem is that when I create a second instance of o_s_child1 and try breeding, it doesn't work.
Any help would be appreciated.

o_slime1 create

alarm[0]=irandom_range(30,120);
direction = irandom_range(0,359);
speed = 0.25;
Clicked = false;

o_slime1 step

var click = mouse_check_button( mb_left);
var hover = point_in_rectangle(
mouse_x, mouse_y,
bbox_left, bbox_top, bbox_right, bbox_bottom
);
if( click && hover){
Clicked = true;
}

o_slime1 alarm

direction = irandom_range(0,359);
speed = irandom_range(0.25,1);
alarm[0]=irandom_range(30,120);


o_slime2 create

alarm[0]=irandom_range(30,120);
direction = irandom_range(0,359);
speed = 1;
Clicked = false;


o_slime2 step

var click = mouse_check_button( mb_left);
var hover = point_in_rectangle(
mouse_x, mouse_y,
bbox_left, bbox_top, bbox_right, bbox_bottom
);
if( click && hover){
Clicked = true;
}


o_slime2 alarm

direction = irandom_range(0,359);
speed = irandom_range(0.75,1);
alarm[0]=irandom_range(30,120);


o_s_child1 create

alarm[0]=irandom_range(30,120);
direction = irandom_range(0,359);
speed = 1;
Clicked = false;


o_s_child1 step

var click = mouse_check_button( mb_left);
var hover = point_in_rectangle(
mouse_x, mouse_y,
bbox_left, bbox_top, bbox_right, bbox_bottom
);
if( click && hover){
Clicked = true;
}


o_s_child1 alarm

direction = irandom_range(0,359);
speed = irandom_range(0.75,1);
alarm[0]=irandom_range(30,120);


o_breed_button left-pressed button pressed

if( o_slime1.Clicked && o_slime2.Clicked){
instance_create_layer(random_range(60, 590),random_range(50,300),"slime", o_s_child1);
o_slime1.Clicked = false;
o_slime2.Clicked = false;
}
//
if( o_slime1.Clicked && o_s_child1.Clicked){
instance_create_layer(random_range(60, 590),random_range(50,300),"slime", o_weird);
o_slime1.Clicked = false;
o_s_child1.Clicked = false;
}
//
if( o_slime2.Clicked && o_s_child1.Clicked){
instance_create_layer(random_range(60, 590),random_range(50,300),"slime", o_death);
o_slime2.Clicked = false;
o_s_child1.Clicked = false;
}
 

TheouAegis

Member
if( o_slime1.Clicked && o_slime2.Clicked)
That is a variable read. That means only one instance of o_slime1 and only one instance of o_slime2 and only one instance of o_s_child can be read from.

You should be saving the id of each slime clicked on in a small array. Having the Clicked variable is fine for doing stuff like drawing a selector box around the slimes, but for the breeding and moving, you should be saving their ids so you can just fetch the only two slimes to worry about. That will also cut your code down quite a bit.
 
That is a variable read. That means only one instance of o_slime1 and only one instance of o_slime2 and only one instance of o_s_child can be read from.

You should be saving the id of each slime clicked on in a small array. Having the Clicked variable is fine for doing stuff like drawing a selector box around the slimes, but for the breeding and moving, you should be saving their ids so you can just fetch the only two slimes to worry about. That will also cut your code down quite a bit.

I really appreciate your reply. I am unsure as how to progress with this but I will do some researches on array.
 
I really appreciate your reply. I am unsure as how to progress with this but I will do some researches on array.
I've found a solution!

In the "o_breed_button left-pressed button pressed" event:

var child1_clicked = false;
if instance_exists(o_s_child1) {
with(o_s_child1) {
if(clicked) {
child1_clicked = id;
clicked=false;
}
}
}

if( o_slime1.Clicked && child1_clicked) {
...
}
 
Top