Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411512 Posts in 69376 Topics- by 58430 Members - Latest Member: Jesse Webb

April 26, 2024, 07:11:31 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)text files in GM; how do I create an array of files from a folder?
Pages: [1]
Print
Author Topic: text files in GM; how do I create an array of files from a folder?  (Read 2256 times)
GregWS
Level 10
*****


a module, repeatable in any direction and rotation


View Profile
« on: August 16, 2008, 04:49:41 PM »

Hi, so I'm working on an ASCII game in GM and I'm setting it up so that users can use Notepad to create additional levels.  So far it's worked pretty well, but I'm having trouble putting together a level select list in the game.  What I'm trying to do is "scan" the Levels folder in the game directory to find out how many level files are in there, and then assign each file a place on an array.  The array part will be easy, but I can't seem to "scan" the folder; when I debug the method I'm using, I just keep getting "0" files back.  Here's my code:
Quote
    levels = 0;
    level_array[0] = file_find_first('working_directory*\Levels   
                     \level_****.txt',fa_readonly);
    while(file_find_next() != ""){
        levels += 1;
    }
    file_find_close();

I'm a little unsure about the part of the function where I used "fa_readonly," and the GM help file is pretty confusing when it comes to some of these file functions; the other options seemed worse.  If you're not familiar with these functions though, I would recommend checking out the GM help file and see what you can make of it.

Thanks!   Beer!
Logged
ஒழுக்கின்மை (Paul Eres)
Level 10
*****


Also known as रिंकू.


View Profile WWW
« Reply #1 on: August 16, 2008, 05:02:24 PM »

There's actually a command for this in GML, search the files section.
Logged

ஒழுக்கின்மை (Paul Eres)
Level 10
*****


Also known as रिंकू.


View Profile WWW
« Reply #2 on: August 16, 2008, 05:03:47 PM »

Found it. Look up file_find_next(), it should work exactly as you need here. When it returns -1, that's the end.
Logged

ஒழுக்கின்மை (Paul Eres)
Level 10
*****


Also known as रिंकू.


View Profile WWW
« Reply #3 on: August 16, 2008, 05:04:50 PM »

Oh, I see you're already using that function, I didn't look at your code.

I suspect your problem is that you need to change != "" to != -1, because it never returns "", it returns -1 when it fails.
Logged

ஒழுக்கின்மை (Paul Eres)
Level 10
*****


Also known as रिंकू.


View Profile WWW
« Reply #4 on: August 16, 2008, 05:05:52 PM »

Wait, no, you're right, it does say it returns an empty string, weird.

Your code should work, the way I'm reading it. I'll test it out and see why it doesn't.
Logged

ஒழுக்கின்மை (Paul Eres)
Level 10
*****


Also known as रिंकू.


View Profile WWW
« Reply #5 on: August 16, 2008, 05:07:18 PM »

I see your problem now.

Change

    level_array[0] = file_find_first('working_directory*\Levels   
                     \level_****.txt',fa_readonly);

to

    level_array[0] = file_find_first(working_directory + '\Levels   
                     \level_****.txt',fa_readonly);

Putting working directory in quotes won't work.
Logged

GregWS
Level 10
*****


a module, repeatable in any direction and rotation


View Profile
« Reply #6 on: August 16, 2008, 08:52:19 PM »

OK, I'll give that a try; thanks so much for all the help!   Kiss

I taught myself GML almost entirely from the help file (and my existing C++ and Java skills), so that's always my first place to check.  Ironically, since learning GML a few years ago, I've completely forgotten how to code in both C++ and Java, so now GML is all I've got left.   Sad
Logged
GregWS
Level 10
*****


a module, repeatable in any direction and rotation


View Profile
« Reply #7 on: August 16, 2008, 09:01:47 PM »

It worked!!!   Kiss Kiss Kiss Kiss Kiss
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic