B
Blaize
Guest
Hey guys,
I'm creating a turn-based combat system that displays which character is next to have their turn somewhere on the screen (as of now, it's in the top left). For this, I'm using a Priority Queue to sort the characters by their Speed stat, and then taking those values and placing them into a List which I then draw on the UI.
The issue I'm having is that the list shows the characters in id order instead of their Speed stat.
This is how it looks:
Here's how I've got the code set up:
How the above code works:
- Spawn the characters(Actors)
- Place them into a ds_priority based on their Speed (random values at this stage)
- Take the max priority value and place it into a list (UIList)
I assumed that since we use ds_priority_delete_max() to place characters into the list, it would place them in order of priority (which is their Speed stat).
Here's how I'm drawing the UI. Eventually, I will have this displaying character portraits instead of text:
Thanks guys
I'm creating a turn-based combat system that displays which character is next to have their turn somewhere on the screen (as of now, it's in the top left). For this, I'm using a Priority Queue to sort the characters by their Speed stat, and then taking those values and placing them into a List which I then draw on the UI.
The issue I'm having is that the list shows the characters in id order instead of their Speed stat.
This is how it looks:
Here's how I've got the code set up:
Code:
var _spawnpoints = instance_number(oSpawnPoint);
for (var i = 0; i<_spawnpoints; i++)
{
var _point = instance_find(oSpawnPoint,i);
instance_create_depth(_point.x,_point.y,0,oPlayer);
}
Actors = ds_priority_create();
UIList = ds_list_create();
with(bCombatActor) //Place into a priority queue based on relevant stats
{
ds_priority_add(mCombat.Actors,id,Speed);
}
//Add the units to the UIList
while(ds_priority_size(Actors)>0)
{
ds_list_add(UIList,ds_priority_delete_max(Actors));
}
ds_priority_destroy(Actors);
- Spawn the characters(Actors)
- Place them into a ds_priority based on their Speed (random values at this stage)
- Take the max priority value and place it into a list (UIList)
I assumed that since we use ds_priority_delete_max() to place characters into the list, it would place them in order of priority (which is their Speed stat).
Here's how I'm drawing the UI. Eventually, I will have this displaying character portraits instead of text:
Code:
for (var i=0;i<ds_list_size(UIList);i++)
{
var _id = instance_find(bCombatActor,i);
draw_text_color(0,i*16,string(_id)+",speed: "+string(_id.Speed),c_blue,c_blue,c_blue,c_blue,1);
}