1. Hey! Guest! The 33rd GMC Jam will take place between May 23rd, 12:00 UTC (Friday noon) and May 27th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

GMS 2 Saving / Loading Button Information

Discussion in 'Programming' started by Gamerev147, May 14, 2019 at 8:46 PM.

  1. Gamerev147

    Gamerev147 Member

    Joined:
    Sep 12, 2016
    Posts:
    430
    I am trying to load information saved for a button.
    In the instance creation code in the room editor, this button is given an ID (var idd). This variable is not defined in the create event.

    Could someone please tell me why this code does not work at all?

    Code:
    ///@description Local Variables
    
    item = "";
    price = 0;
    catagory = "";
    permissions = 0;
    
    draw = false;
    
    alarm[0] = 5;
    
    Code:
    if (file_exists(string(idd) + ".ini")) {
       
        ini_open(string(idd) + ".ini");
        item = ini_read_string(string(item), "item", "");
        price = ini_read_string(string(item), "price", "");
        catagory = ini_read_string(string(item), "catagory", "");
        permissions = ini_read_string(string(item), "permissions", "");
        ini_close();
       
    }
    
    if (item != "") {
       
        draw = true;
       
    }
    Code:
    ///@description Save Information
    
    ini_open(string(idd) + ".ini");
    ini_write_string(string(item), "item", string(item));
    ini_write_string(string(item), "price", string(price));
    ini_write_string(string(item), "catagory", string(catagory));
    ini_write_string(string(item), "permissions", string(permissions));
    ini_close();
    
    Code:
    draw_self();
    
    draw_set_font(fnt_Main);
    draw_set_halign(fa_center);
    draw_set_valign(fa_middle);
    
    if (draw = true) {
    
        draw_set_color(c_white);
        draw_text(x, y - 4, string(item));
        draw_text(x, y + 14, string(price));
    
    }
    Code:
    if (item = "") {
       
        show_message("This template is empty. Press OK to create a new item.");
        item = get_string("Item: ", "");
        price = get_string("Price: ", "");
        catagory = get_string("Catagory: ", "");
        permissions = get_string("Permissions: ", "");
       
        alarm[1] = 3;
       
    } else {
       
        ds_list_add(global.list, string(item), string(price));
        global.subtotal += real(price);
       
    }

    The problem is that no information is loaded. The text on the button doesn't change. Nothing works. Any help is appreciated! Thanks.

    EDIT: The information is saved perfectly fine. It saves with the correct name and everything. It's just that nothing loads.
     
  2. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    1,788
    What does the debugger say all the values are when you step through the load event?
     
  3. Gamerev147

    Gamerev147 Member

    Joined:
    Sep 12, 2016
    Posts:
    430
    I loaded the debug mode, how would I check that?
     
  4. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    1,788
    Short version, but a break point at the start of the alarm[0] (load) event (use F9 or click outside). Then run in debug mode and see what is happening.

    Long version, more useful in the long run, read these:
     
    Japster likes this.
  5. Gamerev147

    Gamerev147 Member

    Joined:
    Sep 12, 2016
    Posts:
    430
    All variables come up empty. What could be causing this?
    It seems like everything is being saved correctly.
     
  6. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    1,788
    what does 'empty' mean? Is it opening the ini file? More specifically, what values does the debugger give for:
    • idd
    • item
    • price
    • catagory
    • permissions
    And when you save saved correctly, you mean you can open the ini file outside of game maker and see everything represented correctly?

    If I had to guess, I'd say that item isn't what it should be so the lookup is failing and you're getting the values set to their default. But looking at what those values are should give you the answer.
     

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