I use a string parser for declaring most of my arrays (unless I need to squeeze the program for speed), there's this one:
Code:
/// string_split_ext(string, *delimiter) = array;
var str = argument[0],
delim = "|";
var arr = 0,
c1 = 0,
p1 = 0;
if (str == "")
{
return undefined;
}
if (argument_count >= 2)
{
delim = argument[1];
}
do
{
var temp = "";
p1 = string_pos(delim, str);
if (p1 == 0)
{
temp = str;
}
else
{
temp = string_copy(str, 1, p1 - 1);
str = string_delete(str, 1, p1);
}
if (string_char_at(temp, 1) == "$")
{
temp = string_delete(temp, 1, 1);
}
else
{
temp = real(temp);
}
arr[c1++] = temp;
} until (p1 == 0)
return (arr);
... Which can be used like this:
Code:
my_array = string_split_ext("$Hello World!|999|$stainedofmind|0|1|2|3|4|$$5.99");
... Where it will return any value starting with '$' as a string, otherwise it will be a real. The last value in the example will also be a string equal to '$5.99'. The problem with this if course is string breaking to add variable values, resource IDs, and running scripts and equations, so I typically use the above in conjunction with a simple script I call 'strf', as below:
Code:
/// strf(str, arguments) = new_str;
var str = argument[0];
var c1 = 1;
repeat (argument_count - 1)
{
str = string_replace_all(str, "$" + string(c1 - 1), string(argument[c1]));
c1++;
}
return (str);
... Which simply replaces all instances of '$x' with the matching value in the arguments, like this:
Code:
player_name = "stainedofmind";
greeting = strf("Hello, $0!", player_name);
... So a combination would be:
Code:
player_name = "stainedofmind";
my_array = string_split_ext(strf("$Hello, $0!|999|$$0|0|1|2|3|4|$$5.99", player_name));
... Of course, careful inspection of the code would show that the last entry could be modified if 6 or more arguments are given to strf. My solution would be to just provide it as an argument itself, like this (just pretend I actually use the extra arguments...):
Code:
player_name = "stainedofmind";
my_array = string_split_ext(strf("$Hello, $0!|999|$$0|0|1|2|3|4|$$6", player_name, 0, 1, 2, 3, 4, "$5.99", "Butts"));
.... Anyway, enough ranting. Use these scripts if you like. One of these days I'll probably just make a combined version of these scripts if I keep using them as much as I have been lately. Maybe even with escape characters.