1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

GMS 2 [Solved] Correct way of restoring original values of list?

Discussion in 'Programming' started by Biosyn, Jul 15, 2019.

  1. Biosyn

    Biosyn Member

    Joined:
    Oct 17, 2017
    Posts:
    43
    I've gone through the manual but I wasn't successful in figuring out the correct way of refilling a ds list with its original values.

    Suppose I have object Bob and Bob starts off with say, 3 apples 2 bananas, 1 cherry. I'd like to make it so that when all fruits have been used up (using ds_list_delete) Bob again gets 3 apples, 2 bananas, 1 cherry. I thought the copying functions might work, but nothing happens.

    Here is what I have:

    Create Event:

    Code:
    fruit_list_source=ds_list_create();
    
    //Bob
    ds_list_add(fruit_list_source,
    app,
    app,
    app,
    ban,
    ban,
    chr,
    )
    
    fruit_list_main = ds_list_create();
    ds_list_copy(fruit_list_main, fruit_list_source);
    ;
    Key Press Event:

    Code:
    if ds_list_size(fruit_list_main)>0
        {ds_list_delete(fruit_list_main,0)}
        else
        {   
        ds_list_destroy(fruit_list_main);
        fruit_list_main = -1;       
        
        fruit_list_main = ds_list_create();
        ds_list_copy(fruit_list_main, fruit_list_source);
        }
    Thank you in advance.
     
  2. TheSly

    TheSly Member

    Joined:
    Jan 16, 2017
    Posts:
    997
    Your code works when I tested it. chr is a reserved word though, so I changed it to che, and made sure I had assigned variables to the values of app, ban and che (0, 1, 2).
    At the end of your keypress event, you can use a script to show the output of the ds_list.

    I wrote this one, which works well.
    Code:
    /// @desc ds_list_out();
    /// @arg item
    
    //takes input of ds_list and outputs it to console window
    var _ds = argument0;
    
    if ds_exists(_ds, ds_type_list) {
        show_debug_message("DS_LIST Output : ");
        for (var i = 0; i < ds_list_size(_ds); ++i) {
            show_debug_message(_ds[|i]);
        }
    }
    
    
     
    Biosyn likes this.
  3. Biosyn

    Biosyn Member

    Joined:
    Oct 17, 2017
    Posts:
    43
    I tried using the example variables with the fruits and it seems to work now. Strange. Not sure what the problem was, maybe there was some issue with the actual variable names.

    And thanks for that script! Just added it to my project.
     

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