Login | Register

File listing

June 29, 2006, 12:24 by Calle
[loading]
-->
If you have a save function in your game or program, or if you want to have it, then you most certainly want the loading to be as painless as possible as well. Here's how you can do this in a simple but yet very effective way.

<div style="clear: both;">c = 0;
file[c] = file_find_first("files*.*",fa_archive);
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 file by entering the number:#"+exi_files,"";)
</div>

As you can see I got two loops: the first one to find the files, and a second one to arrange them in a list. Although I use the 'while' statement 'for' will do fine as welll. You can specify filetype by changing the mask and the attribute. For an example, if your save file has the extension ".save" it'd be 'file_find_first("files/*.save",fa_archive);' instead.

Notice that although I don't use my array in the presentation, I still got a number presenting it and will need to call it later on, because if the user enters five, then the file he/she wants to load is file[5]...

Your free to use this, although, as always, we would like credits.

Comments

Loading comments... [loading]
.
Users logged in:

game maker articles, game maker examples, game maker tutorials, gmtutorials, game maker questions and answers, game maker crash course, how to create games