• 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 [HELP]Choosing Instance_ID for specific object

R

Ryscale

Guest
Hello everyone

Firstly I would like to introduce to you my problem, at first i was using a line of code which was for a object to go to point A and go to point B( point A and B are objects). There are multiple Point B's in the map near one another but the object only picks 1 the same one every time.

Now that i added a picker which choose's the ID of a flower and does the exact thing but now its just broke, below is the code.

>>>>>>>>>>>>>>I added this within my create event..

flower1 = inst_4D092D21;
flower2 = inst_536C30F0;
picker = choose(flower1, flower2);

>>>>>>>>>>>>>and this is the step event

///moving to flower

if (land = false and start = true) {
direction = point_direction(x,y,picker.x,picker.y);
}

///if collide with flower move to hive

if (land = false and place_meeting (x,y,picker)){
land = true;
start = false;
}


///moving to beehive

if (land = false and start = false){
direction = point_direction(x,y,o_bee_col.x,o_bee_col.y);
}


///if collide with hive move to flower

if (land = false and place_meeting (x,y,o_bee_col)){
land = true;
start = true;
}

///timer
if (land = true){
speed = 0;
if (timer == 0){
land = false;
speed = 1;
picker = choose(flower1, flower2);

}
}

>>>>>>>>>>>>>>>>alarm 0 event

alarm[0] = irandom_range(5,15);
if (land = true){
timer -= 1;
}
 

CloseRange

Member
Code:
picker = instance_find(obj_flower, irandom(instance_number(obj_flower) - 1));
this will select a random flower and return it.
I'm not sure what you were doing with the inst_4D092D21 unless that's a really really weird variable, or object name that you came up with
I know you were probobly trying to use the 'id' variable that comes when you print 'id' or when you look at the room editor but you can't directly use the id like that.

EDIT:
i guess i should elaborate.
instance_find - returns the n'th instance of a specific object (so like the 3rd or 4th flower in your room)
irandom - returns a random number from 0 to n.
instance_number - returns how many instances of a specific object there are (in this case how many flowers are in the room)

so we use irandom to choose a number from 0 to however-many-flowers-there-are
then we use that to find that specific flower.

So if there are 5 flowers it choose a number from 0-4
if it chose, lets say 2, then it would find the 2nd flower (well actually 3rd because it starts at 0) using instance_find
 
Last edited:
R

Ryscale

Guest
Code:
picker = instance_find(obj_flower, irandom(instance_number(obj_flower) - 1));
this will select a random flower and return it.
I'm not sure what you were doing with the inst_4D092D21 unless that's a really really weird variable, or object name that you came up with
I know you were probobly trying to use the 'id' variable that comes when you print 'id' or when you look at the room editor but you can't directly use the id like that.

EDIT:
i guess i should elaborate.
instance_find - returns the n'th instance of a specific object (so like the 3rd or 4th flower in your room)
irandom - returns a random number from 0 to n.
instance_number - returns how many instances of a specific object there are (in this case how many flowers are in the room)

so we use irandom to choose a number from 0 to however-many-flowers-there-are
then we use that to find that specific flower.

So if there are 5 flowers it choose a number from 0-4
if it chose, lets say 2, then it would find the 2nd flower (well actually 3rd because it starts at 0) using instance_find
Firstly thank you for replying and sorry for being complete noob where about's do i put that line of code you sent me? Create event?

EDIT: ive added it to my create event and (im not sure if i need to refresh it everytime) my timer event. But still the bee's wont leave the hive to return to the flowers.
 
Last edited by a moderator:

CloseRange

Member
right now you have:
Code:
picker = choose(flower1, flower2);
in order to select a random flower.
Code:
picker = instance_find(obj_flower, irandom(instance_number(obj_flower) - 1));
this is just how you should be picking a flower,
 
R

Ryscale

Guest
right now you have:
Code:
picker = choose(flower1, flower2);
in order to select a random flower.
Code:
picker = instance_find(obj_flower, irandom(instance_number(obj_flower) - 1));
this is just how you should be picking a flower,
Again thank you for replying, i was able to achieve the random objects through the code you suggested, but the bees still won't go back to a flower after visiting the hive. I checked on the debugger the timer works perfectly. But the timer will not work once it gets to the hive. (it worked perfectly before when picker was just the object)
 

CloseRange

Member
you have 2 places that you do:
Code:
picker = choose(flower1, flower2);
once in the create and once in the end of the step. Did you make sure to replace both?
 
R

Ryscale

Guest
you have 2 places that you do:
Code:
picker = choose(flower1, flower2);
once in the create and once in the end of the step. Did you make sure to replace both?
Yes! I replaced them both, but for some reason the timer doesnt work since i changed the object to picker.
 
Top