Hey there!
After realizing how underdocumented some of my things were, I thought I'd make some use of the features I added in like... 2006, and share some fairly useful VC with you folks.
Firstly, I present DictConstruct, which can create and populate a dictionary in the same call.
// DictConstruct
// Constructs a dictionary and populates it using the string arguments given to it.
// Pass: args - strings of the form "key:value"
// Returns: A dictionary handle populated with the key-to-value mappings you supply.
int DictConstruct(... args)
{
int i;
int dict = DictNew();
string k, v;
for(i = 0; i < args.length; i++)
{
if(args.is_string[i])
{
k = GetToken(args.string[i], ":", 0);
v = TokenRight(args.string[i], ":", 1);
DictSetString(dict, k, v);
}
else
{
Exit("DictConstruct: Argument " + str(i) + " must be a string value.");
}
}
return dict;
}
Here is an example usage:
int dict = DictConstruct("name:Bob", "job:Fighter", "attack:54");
Secondly, I give you a fairly simple (but possibly handy) varargs function for logging text.
// Print
// Logs a message from a list of mixed string/int arguments and prints it with tabs
// Pass: args - The arguments to print
void Print(... args)
{
string s;
int i;
for(i = 0; i < args.length; i++)
{
if(args.is_int[i])
{
if(i) s += " ";
s += str(args.int[i]);
}
if(args.is_string[i])
{
if(i) s += " ";
s += args.string[i];
}
}
Log(s);
}
Example usage:
Print("Hey look it's like Log() except for ", 1, " thing, it takes varargs");