DS_lists and sorting...

Discussion in 'Programming' started by Niels, Sep 2, 2017.

  1. Niels

    Niels Member

    Joined:
    Jun 22, 2016
    Posts:
    827
    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:
    step event:
    draw event:

     
  2. Niels

    Niels Member

    Joined:
    Jun 22, 2016
    Posts:
    827
    .
     
    Last edited: Sep 2, 2017
  3. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,906
    Why don't you use a queue or stack? What is the log_order variable even for?
     
  4. Niels

    Niels Member

    Joined:
    Jun 22, 2016
    Posts:
    827
    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.
     
  5. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,906
    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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice