• Hey! Guest! The 37th GMC Jam will take place between May 28th, 12:00 UTC and June 1st, 12:00 UTC. Why not join in! Click here to find out more!

GMS 2 Saving / Loading Button Information

Gamerev147

Member
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.
 

samspade

Member
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.
 
Top