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

DS_lists and sorting...

Niels

Member
Hi everyone,

I'm trying to learn more about GM:studio's data structures, so I decided to make a turn based RPG( light) project and use arrays and DS_lists in it.

I build a small setup for what's going to be a combat log for the turn based combat with a DS_list.
Problem with it is that I want to make it scroll up like those old MUD's and RPG's like Baldur's gate did. (newest attack is on the bottom line of the log, and older entries are placed above it).

I managed to do this with the DS_list_sort option and put it to descending.
Problem is that the basic attack line includes the damage variable: " you attack thin air for" + string(dmg) + "damage!");
And that actually messes the whole order of entries up....

This is my code:

Create event:
stepcounter = 0;
time_line = 60;
dmg = 0;
battle_log = ds_list_create();
log_order = 1;
step event:
//destroy
if mouse_check_button(mb_left) {
global.halt = false;
ds_list_destroy(battle_log);
instance_destroy();
}

//timeline
stepcounter ++;

if stepcounter == time_line {
dmg = irandom(5); //will change when weapons are in
ds_list_add(battle_log,string(log_order) + " you attack thin air for" + string(dmg) + "damage!"); //template will change!
stepcounter = 0;
log_order ++;
ds_list_sort(battle_log, false);
}
draw event:
draw_self();
for (i = 0; i < ds_list_size(battle_log); i ++ ) {
draw_set_halign(fa_middle);
draw_text_transformed(x,y + 60 - (10 * i), ds_list_find_value(battle_log,i),0.5,0.5,0);
}

 

Niels

Member
Why don't you use a queue or stack? What is the log_order variable even for?
thanks for the reply,

The log order was to count up the DS_list entries so I could sort them in a ascending manner

basically I want the following to happen:
the following happens every attack (triggers on time_line which is a turn)
you attack <insert monster> for <dmg> damage! <== this is the oldest attack prompt.
you attack <insert monster> for <dmg> damage!
you attack <insert monster> for <dmg> damage! <== this is the one before that
you attack <insert monster> for <dmg> damage! <== is the newest attack prompt

the next time time_line triggers it ads a new line at the bottom and all other (older) attacks move 1 line higher.
 

TheouAegis

Member
Then just use a ds_list as-is. Whenever you add a value to a list using ds_list_add(), it gets appended to the end of the list. When the size of the list gets too big, remove index 0 from the list using ds_list_delete(). All the contents will automatically move up after that.
 
Top