Random Semi-Useful Methods
by JeffH · 12/10/2011 (10:40 am) · 0 comments
My first resource!
These are some custom useful methods i made. See what you can do with them, and have fun experimenting with them.
gets a random string, specify the length in the length parameter
for convienence, just compiles a cs or gui file into a dso
searches a file, goes with makeDso method.
These are some custom useful methods i made. See what you can do with them, and have fun experimenting with them.
gets a random string, specify the length in the length parameter
function getRandomString(%length) {
//lets not go too insane here...
if(%length > 10) {
warn("Warning, getRandomString(%length)'s length is too long, making it 10...");
%length = 10;
}
%letters = "a b c d e f g h i j k l m n o p q r s t u v w x y z 1 2 3 4 5 6 7 8 9 0";
for(%i = 0; %i < %length; %i ++) {
for(%a = 0; %a < 4; %a ++) {
%Randomchar = getRandom(0, 35);
}
%char = getWord(%letters, %Randomchar);
%string = "\"" @ %string @ %char @ "\"";
}
if(%string $= "" || strLen(%string) > 10)
return -1;
return %string;
}for convienence, just compiles a cs or gui file into a dso
function makeDso(%file, %extension) {
%uncompiledFile = searchFile(%file, %extension);
if(isFile(%uncompiledFile)) {
%word = getWord(%uncompiledFile, 1);
if(%word $= ".cs" || %word $= ".gui") {
%name = getWord(%uncompiledFile, 0);
//sanity checking...
if(%name $= "")
return error("Error, the file can't be located.");
echo("Compiling file: " @ %name @ ".");
compile(%uncompiledFile);
} else {
return -1;
}
}
}searches a file, goes with makeDso method.
function searchFile(%file, %ext) {
%named = findFirstFile("*/" @ %file @ "." @ %ext);
if(%name !$= "") {
echo("Found file:" SPC %file @ "." @ %ext);
return %named;
}
return -1;
}About the author
19 year old who loves programming with Torque3D!
