pick_random_file() and "Reunited" forum

Posted by Jesper on May 14, 2007, 2:52 p.m.

Hey everyone… as this script is too small to post in an example or project, thought I'd just post it in a blog.

Quote: From GMC Topic

Hey everyone!

I wrote a script for picking a random file with attributes you specify on another forum (Reunited) for "Edge". Here it is:

{
///////////////////////////////////////////////////////////////////////////////////////////////
// pick_random_file(directory,filter,attr)
///////////////////////////////////////////////////////////////////////////////////////////////
// returns a random file from the directory, filter and attributes you choose
///////////////////////////////////////////////////////////////////////////////////////////////
// argument0: directory: directory to search in (example: "D:My Documents:examplefolder")
///////////////////////////////////////////////////////////////////////////////////////////////
// argument1: filter: only search for the sepcified file extension (example: "jpg")
///////////////////////////////////////////////////////////////////////////////////////////////
// argument2: attr: search for the following optional files with special attributes too:
//// fa_readonly (read-only files), fa_hidden (hidden files), fa_sysfile (system files), 
//// fa_volumeid (volume-id files), fa_directory (directories), fa_archive (archived files)
//// (those are all constants, so if you type them right they will be colored red ;))
//// (example: fa_readonly+fa_sysfile+fa_archive)
///////////////////////////////////////////////////////////////////////////////////////////////

var dir,filt,attr,fnum,pickfile;

dir=argument0
filt=argument1
attr=argument2
fnum=0

file_find_first(dir+"*."+filt,attr)

while !(file_find_next()="")
    {
    fnum+=1
    }
file_find_close()

pickfile=round(random(fnum))

openfile=file_find_first(dir+"*."+filt,attr)

repeat(pickfile)
    {
    openfile=file_find_next()
    }
file_find_close()

return(openfile)
}

And here is the example file (includes the GM6, the GMK, and 3 example jpg files to choose from):

Download pick_random_file.zip

I hope you like it :D,

Jesper

On other news, probably lots of you know "ThatGamesGuy", and maybe also his forum. And as you might also now, he closed down all stuff (teams,ezine,forum,contests,etc.) temporarily (probably forever but the site sais "have been discontinued indefinitely").

A few days after the forum closed down, people decided that a new forum should be created as sort of a replacement of the TGG-Forum. The teams and contests are continued/redone here too, so don't be afraid of Barnstormer: 1920 never being finished :D! You currently can't apply but you can in the near future probably (more information on former "TGG Teams" stuff in a blog by the "TGG Team A" account soon :)).

If you would like to join or take a look at the forum, go here.

I'm continuing on GameMaker Bounding Box too. Expect for the next update:

- Locate x, y, z (relative/absolute)

- Scale x, y, z (transform around: grid center, individual centers, selections center)

- Rotate x, y, z (transform around: grid center, individual centers, selections center)

- …?

Probably an update will be available soon :D!

C ya all later,

Jesper

Comments

poultry 16 years, 11 months ago

random files are pointless

Jesper 16 years, 11 months ago

Theoretically, it could be used for lots of things. Plus, Edge needed it, so it at least has one purpose [:D].

Gamer3D 16 years, 11 months ago

ChIkEn, you are again showing your lack of understanding of some subjects. Here's an example of a use for a random file picker:

You are making a 3D game. You have made interchangeable scenery (one object can use many different scenery objects). Now you want to place some scenery. Instead of specifying a scenery item, you need only place the object, and it will pick a file.

Kaz 16 years, 11 months ago

Or put the filenames in an array and pick a random one =/

poultry 16 years, 11 months ago

So you would load a file for every tree object? Yeah right.

noshenim 16 years, 11 months ago

Quote:
random files are pointless
random loaded music/external enemy ai/external map…

noshenim 16 years, 11 months ago

so if you have a game with 50 20kb external maps you can pick a random one to load instead of load them all and then pick one to save time….

melee-master 16 years, 11 months ago

Chiken got owned.

[deleted user] 16 years, 11 months ago

I don't see the point of the script, anything you needs it for could be done Kaz's way.

Jesper 16 years, 11 months ago

And it can be done this way. What's your point…