My
Heart's Club Revisted heavily uses files, folders and tags for different media like images, animated gif, clips and videos. So I had similar problems. I wrote my own functions to get what I want.
comonFunctions.ListFiles() only lists files, not folders...
comonFunctions.ListSubFolders() only lists subfolders, not files...
Both functions return a string, not an array.
So you have to parse the string to create an array with the individual file- or foldernames.
Example for files:
Code: Select all
function fGetFilesArray(vFolder) {
var vFilesList = comonFunctions.ListFiles(vFolder);
var vFilesArray = [];
if (vFilesList.length() == 0) {
// Folder contains NO Files
vFilesArray = [];
} else {
if (vFilesList.search(",") == -1) {
// Folder contains one subfolder
vFilesArray = [vFilesList];
} else {
// Folder contains multiple subfolders
vFilesArray = vFilesList.split(",");
}
}
return vFilesArray;
}
Example for folders:
Code: Select all
function fGetSubFolderArray(vFolder) {
var vSubFolderList = comonFunctions.ListSubFolders(vFolder);
var vSubFolderArray = [];
if (vSubFolderList.length() == 3) {
// Folder contains NO Subfolder
vSubFolderArray = [];
} else {
vSubFolderList = vSubFolderList.substring(2, vSubFolderList.length()-2);
if (vSubFolderList.search("\", \"") == -1) {
// Folder contains one subfolder
vSubFolderArray = [vSubFolderList];
} else {
// Folder contains multiple subfolders
vSubFolderArray = vSubFolderList.split("\", \"");
}
}
return vSubFolderArray;
}
Then you could for example check each filename if it has the "correct" filetype by checking the ending (.jpg for example). And lastly you could combine foldernames and filenames into a new array containing each file including its complete folderpath (for example: "random\solo\babes\hot1.jpg"). Pick an random Elelement from that array using the range (0, Array.length+1) and you can directly use the resulting string to add it as media to your pages.
For my
Heart's Club Revisted: At the start of the game and as part of the settings the player can initialize or refresh the random media files. The script then searches all random media files, sorts them into their categories and saves arrays for each individual category containing the list of all files (including the folderpath). So i have all random media files ready to go when i need them in the game and this way i make sure, a wrong filetypes or empty folders don't break the game. It makes in general the handling of the different files much easier.
I hope this helps a bit.