You are not logged in.
Pages: 1
Hi everyone, here's my contribution to gmlscripts: directory_create_missing. The script is fairly easy to understand. What it does is creating every missing directory in a given path. For example, in a game, if you want to let the user to create screenshot and you want to store them in a multi-directory path such as: /Data/Screenshot/Zerg/. This works fine if the directory are already there but what happens if the user deleted those? Game Maker will throw an error. What I did for my game for online sharing maps that has to be stored in custom directories, I created a script that will create the directories which will allow anything to be stored in a given path even thought the directories did not exists.
Here's the script finally:
//arg0: Path
var fname, directory, i;
fname = string_replace_all(argument0,"\","/");
directory = "";
i = 0;
repeat(string_count("/",fname))
{
directory += "/"+reflect_nextvar(fname,i,"/");
if not directory_exists(working_directory+directory) then
directory_create(working_directory+directory);
i += 1;
}
However, the script uses another script which Fred from the Reflect community provided me. Here's his script:
//retrieve values from a list of values seperated by the character designated in argument 2
//returns the value if it exists, and a blank string if it does not
// argument list
// 0 - input string
// 1 - position of the variable in the string (starting at 0)
// 2 - the character that seperates values from one another ("," "|" etc.)
var temp_index,input_string,temp_string,i;
input_string = argument0;
temp_index = argument1;
search_char = argument2;
for(i=0;i<=temp_index;i+=1) {
if(string_pos(search_char,input_string) != 0) {
temp_string = string_copy(input_string,1,string_pos(search_char,input_string)-1);
} else {
temp_string = input_string;
}
input_string = string_delete(input_string,1,string_length(temp_string)+string_length(search_char));
}
return temp_string;
Hope you like it. We can now make sure it is 100% liable and then format it correctly to finally release it .
Miguel
Offline
It's very useful for installing files. working_directory forces it to only be done in the game folder, which may be a good thing for noobs. we can aleways remove that. good job
Offline
This is a really good idea for a script.
That second script from Fred is a simpler version of an existing script here: string_parse_single
It could be substituted for Fred's, but I wonder if it would be worth the effort to just merge the everything into a single directory creation script.
Abusing forum power since 1986.
Offline
Thanks! As for the working_directory part, we could always remove that as you said icuurd12b42. And as for your suggestions, xot, I'll look into it and make some tests . OR we could always make people use the script already on the website.
I'll post the updated script soon.
Offline
Pages: 1