The Daily Click ::. Forums ::. Klik Coding Help ::. Choosing a random file
 

Post Reply  Post Oekaki 
 

Posted By Message

Hplkopra



Registered
  30/08/2002
Points
  65
22nd November, 2003 at 14:33:15 -

How can I make the game/application get a random file from a directory? Like if the 'random' button is pressed, it gets just some random file from the directory and then says or something. Can you help?

 
Try to solve the mystery of this signature.

Weston L



Registered
  16/12/2002
Points
  1603
22nd November, 2003 at 15:10:58 -

I don't think it's possible... but why would you want to?

 
n/a

ShadowCaster

Possibly Insane

Registered
  02/01/2002
Points
  2203
22nd November, 2003 at 19:19:44 -

It is possible. The way I would do it is create a list box (it can be "invisible at start of frame" if you like).

In the event editor (or behaviour editor) have it load the file list from the specified directory at the start of the frame.

Now, select a random number that is from 0 to the number of lines in the list box.

Read the line based on the random number and bob's your uncle.

Mike

 
"Now I guess we're... 'Path-E-Tech Management'" -Dilbert

Assault Andy

Administrator
I make other people create vaporware

Registered
  29/07/2002
Points
  5686

Game of the Week WinnerVIP Member360 OwnerGOTM JUNE - 2009 - WINNER!GOTM FEB - 2010 - WINNER!	I donated an open source project
23rd November, 2003 at 01:53:35 -

SC - That is exactly what i thought of before i opened this thread!

 
Creator of Faerie Solitaire:
http://www.create-games.com/download.asp?id=7792
Also creator of ZDay20 and Dungeon Dash.
http://www.Jigxor.com
http://twitter.com/JigxorAndy

ShadowCaster

Possibly Insane

Registered
  02/01/2002
Points
  2203
23rd November, 2003 at 04:05:59 -

Andy:

Something very important I forgot to mention is that if you have selected the checkbox in the listbox properties that says "1-Base Index" then you will need to read the line from the listbox based on Random + 1. This is because instead of being from 0 to Total - 1, a 1-base index uses numbering from 1 to Total.

If you dont have it selected, use the code I said (which is from 0 to Total - 1).

Your game wont crash if you have it either way, it simply wont load a file if it happens to choose the 1 number that is outside the boundary.

Mike

Just to reiterate so I make sense:

0-Base Index
"open " + appDrive$ + appDir$ + GetLine(Random(NBLines("Listbox"))) " alias music"

1-Base Index
"open " + appDrive$ + appDir$ + GetLine(Random(NBLines("Listbox")) + 1) + " alias music"

Please note that the above lines are not exact code as you would enter them, you will need to check the NBLines and GetLine functions using the Retrieve Global Value button in the Expression Editor. Plus the command itself will change depending on what object your using to play the music file. In this example I've demonstrated with the MCI object.

 
"Now I guess we're... 'Path-E-Tech Management'" -Dilbert

Hplkopra



Registered
  30/08/2002
Points
  65
23rd November, 2003 at 06:13:46 -

Thanks!
Weston L: Yhis is for a level selection. If you press the random button it vhooses a random level.

 
Try to solve the mystery of this signature.
   

Post Reply



 



Advertisement

Worth A Click