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

Legacy GM How to Input DS List(s) into an Ini file?

L

learn2draw

Guest
Hello, reader!

I found a code for keylogging online (http://gamedev.stackexchange.com/questions/25881/how-can-i-log-key-presses-in-game-maker), and wish to send the data (in DS lists) that it collects to an ini file which I have set up. I have tried following the instructions in the GameMaker manual, but my ini file reads:

upload_2017-2-4_12-10-28.png

My scr_savegame reads:

Code:
if (file_exists("Save.sav")) file_delete("Save.sav");
ini_open("Save.sav");
var keyCodes = ds_list_create();
var keyTimes = ds_list_create();
ini_write_real("Save1","ds_list_create();",keyCodes);
ini_write_real("Save1","ds_list_create();",keyTimes);
ini_close();
My scr_loadgame reads:

Code:
if (file_exists("Save.sav"))
{
    ini_open("Save.sav");
    var keyCodes = ini_read_real("Save1","ds_list_create();",rm_1);
    var keyTimes = ini_read_real("Save1","ds_list_create();",rm_1);
ini_close();
    room_goto(LoadedRoom);
}
else
{
    //do nothing
}
Please forgive me as I am new to GameMaker and programming as a whole, and so please be as specific as possible in regards to what my next step should be. I would like to have the "At frame 159 you pressed key F (Code: 14)" type of text in my ini file.

Thank you so much for your time! Help is very much appreciated.
-l2d
 
Z

zendraw

Guest
you shuld save the list with ds_list_write and load it with ds_list_read
ds_list_write turns your list into a string so you shuld save it as ini_write_string
then when loading var codes=ini_read_string
and then ds_list_read()
look up the functions in the manual.
 
L

learn2draw

Guest
Thanks for responding! I took your advice and came up with the following code:

scr_savelist:

Code:
if (file_exists("Save.sav")) file_delete("Save.sav");
var str;
ini_open("Save.sav");
str = ds_list_write(keyCodes)
str = ds_list_write(keyTimes)
ini_write_string("Save1","keyCodes",str);
ini_write_string("Save1","keyTimes",str);
ini_close();
scr_loadlist:

Code:
if (file_exists("Save.sav"))
{
    keyCodes = ds_list_create();
    keyTimes = ds_list_create();
    ini_open("Save.sav");
    var str = ini_read_string("Save1","keyCodes","");
    var str = ini_read_string("Save1","keyTimes","");
    if str != ""
        {
        ds_list_read(keyCodes,str);
        ds_list_read(keyTimes,str);
        }
    ini_close();
    room_goto(LoadedRoom);
}
else
{
    //do nothing
}
However, my ini file is coming up empty with no data? Do you have any suggestions in regards to what may be wrong with my code? Thanks!
 
Z

zendraw

Guest
what do you mean its coming up empty? is the file itself empty or the loaded variables?
i cant see a problem in your code, but you can use show_message() to pinpoint where the problem is
for instance after you load the string in the variable str write show_message(string(str)) to see the whats the variable holding.altho you can also enter the directory of the ini file an open it and see whats inside it, usually its a bunch of 0`s and other characters/numbers.
if everything is loaded fine you can check the grid`s size.
you can debug this way the saving also. its very easy to pinpoint. but when you use show_message you shuld load your game in windowed mode, just to spare the game to switch to windowed becouse show_message aways switches to windowed.
 
P

Poddington

Guest
One thing I can see is when you create var str you then assign a list to it twice before saving and loading. This means the keyCodes list information is overwritten by KeyTimes before you are saving it or loading it.
 
L

learn2draw

Guest
Yes, the file itself is coming up empty. I am implementing the show_message() function right now.

This is what my code looks like right now:

scr_savelist:

Code:
if (file_exists("Save.sav")) file_delete("Save.sav");
var str;
ini_open("Save.sav");
str = ds_list_write(keyCodes);
show_message("keyCodes =" + string(str));
ini_write_string("Save1","keyCodes",str);
ini_close();
scr_loadlist:

Code:
if (file_exists("Save.sav"))
{
    keyCodes = ds_list_create();
    ini_open("Save.sav");
    var str = ini_read_string("Save1","keyCodes","");
    if str != ""
        {
        ds_list_read(keyCodes,str);
        }
    ini_close();
    room_goto(LoadedRoom);
}
else
{
    //do nothing
}
Thank you for your help, but I feel like I am not making much progress. Would you happen to know of a simpler way that I can keep track of (and record in an ini file) the key that was pressed during the game and the frame (or time) at which it was pressed? Perhaps something along the lines of... (although I have not been so successful using this method either ( ^_^ ; )):

Code:
if (file_exists("Log.sav")) file_delete("Log.sav");
ini_open("Log.sav");
if keyboard_check_pressed(vk_up)
    {
        ini_write_real("Save1","up",global.up);
    }
    if keyboard_check_pressed(vk_left)
    {
        ini_write_real("Save1","left",global.left);
    }
    if keyboard_check_pressed(vk_right)
    {
        ini_write_real("Save1","right",global.right);
    }
ini_close();
Thanks!
 
Top