<div style="clear: both;">I use the following code to compile a list of all my save files and present it to the user:
c = 0;
extension="extension";
file[c] = file_find_first("files/*."+extension,fa_archive);
*/ < just ignore this line;
while !(file[c] == ""
{c +=1;
file[c] = file_find_next();
}
file_find_close();
d = 0;
exi_files = "";
while(d<c) {
exi_files += string(d) +". "+file[d]+"#";
d+=1;
}
selected_nr = get_integer("Choose a file and then enter the number
below (use unexisting number to cancel):#"+exi_files,""
;</div>It will get all names of the files in the files folder that got the specified extension. I am doing this with two loops: the first one is using my mask and attributes to find all the files, it sorts them into an array. The second will go through that array and add them to a list and it will also add a new line character, this way I will be able to draw the list as one. That is what I do in get_integer. It will look something like this:
0. Custom name 1
1. File2
2. Custom name 3
Etc. If the user selects 0 we can figure out what file that is by looking back at the array:
if (selected_nr<=c) {
file = file_text_open_read("files/"+file[selected_nr]);
}
I add an If statement, with proper condition, because we do not actually know that the user will enter one of the numbers that are displayed. He might enter any number, by mistake perhaps, and if we try to open that file it will cause an error. This will work though.
Note that you may also use the first part of the code, this last open-up-file code, but present it anyway other than in a pop-up. This method is highly sophisticated and it’s possible to present the info in anyway, as you got it in an array.
Example:
http://gmtutorials.com/files/listex.gm6
Comments
Loading comments...