• 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 Multiple instances of the same object taking turns at different times?

D

denpa

Guest
I have multiple instances of the same objects. My game is a turn based rogue like (grid movement) and I'm not sure how I would go about making each object take their turns one after the other if they are the same object with the same variables? I would go down a list of the objects according to a "speed" stat, but what if multiple objects have the same speed? The objects would make their move, but if two or more objects have the same speed, they would move at the same time.

I'm really not sure where to even begin.
 

Yal

šŸ§ *penguin noises*
GMC Elder
Put all objects in a priority queue (there's a data structure for that, check the manual for details) sorted by the speed, then pick one at a time from the queue and have them do their turn. Don't let the next object have their turn until the current one finishes. (You probably want to have all objects call a common script that tells the control object that their turn is finished or something to streamline the process)
 
D

denpa

Guest
I've been reading up on instance ids and ds_priority, but I'm not really sure how to tell my objects listed to make a move. For now I have it set up so that if the player's "move" variable is true then my enemy object can move. I added a speed stat to my objects as well (stat_spd). I'm not really sure if I'm using it properly.

I have an invisible controller object that creates the priority queue and assigns it to a global variable called global.turn_order. I have both my player object and my enemy add to the priority queue during their step events when they are not moving. The player has a stat_speed of 2 while the enemies have it set to 1. I add them to the priority queue like this:

Code:
if move == false{
    ds_priority_add(global.turn_order , self.id , self.stat_spd);
}

This should add their instance id as the value and their speed as the priority. But now how do I tell the game to move them in order? I was trying something out like this in the controller object's step event:

Code:
while (!ds_priority_empty(global.turn_order) and obj_player.move == true){
    ds_priority_find_max(global.turn_order);
}
Of course this does nothing since I'm just telling it to find the max value which should be my player object's speed, but what I have no idea what I should do after that. How do I pick my objects one at a time in order?

Thank you for the help so far.

EDIT: Literally after posting this I came up with the idea of using ds_priority_find_max() to check if the ds_priority is equal to the object's id.

Code:
if moving and ds_priority_find_max(global.turn_order) = id{
    movement code
}
Now my problem is that not all the instances move. I added 9 instances of my enemy object to the room, but only 6 of them move. The three that don't move are also the last 3 that were added to the room. What could be causing this?
 
Last edited by a moderator:
Top