Gm Problem

Posted by Kaz on May 13, 2006, 9:46 p.m.

You all know how instance_nth_nearest works right? It finds the id of the nth object object where n is a number put in by the user. What I want is to find the first 3 files that have certain extension(.sav). Im not too good with files in GM so any help would be appreciated.

Comments

twisterghost 18 years, 6 months ago

If you tell me what you want it to do, I can show you how to do it in the patented TG way….

melee-master 18 years, 6 months ago

By using the file_find functions, you could use file_find_next three times, and record it each time to get the first three. I'll make an example or something.

twisterghost 18 years, 6 months ago

Melee, why do you always have to brainwash people into thinking they need to make exess hard code and such?

:P

melee-master 18 years, 6 months ago

//Script Name: file_get_nth_amt
//Author: Melee-Master

var n,a,file,i,_max,ret;
    n = argument[0]; //The file to start from
    a = argument[1]; //The amount of files from n
    i = 0;
    file[0] = file_find_first("*.sav",0);
    do
    {
        i += 1;
        file[i] = file_find_next();
    }until(file[i] == "")
    _max = i - 1;
    ret = "";
for(i = n; i < n + a; i += 1)
{
    if(i > _max)
    {
        ret += "No file #";
    }else
    {
        ret += file[i] + "#";
    }
}
return ret;

I tested that, and it seems to work fine, although I may have misunderstood your question. Heh.

Kaz 18 years, 6 months ago

That only works if the files are like-

file1

file2

file3

Right?

Mine could have different names…

melee-master 18 years, 6 months ago

Don't worry, even they have different names it's fine.

Kaz 18 years, 6 months ago

Im a little confused as to how I would use it. I have 3 save slot objects, each one finds a different file(if any) and draws the file name. Im thinking this might be a problem since its all 1 object doing the same thing at once.

Kaz 18 years, 6 months ago

Sweet I got it! I just had the file variable set when I created the save file objects in another object. Thanks for you help though.

melee-master 18 years, 6 months ago

Here's an example:

You put 0 as the first argument, and 3 as the second argument to return the first three files found (if there were only two files, it'd return Null, which I should probably fix…). Now, if you had put 1 as the first argument and 3 as the second argument, it'd find the three first files from the second file.

The value it returns is a string with each file on a new line.

melee-master 18 years, 6 months ago

Oh, I posted a bit too late, xD.