zarqon
Well-known member
Okay, here's the latest scripting challenge for which I've been unable to come up with a suitable solution. I present it here for the resident wizards, gurus, et. al.
I use this function a lot to load maps from my Map Manager:
I would love to put this function in ZLib, where I could just have it once for all my scripts. Note that everything inside this function is completely portable. But the problem is that the map may be of any structure -- i.e. it's not always string[string], it may be familiar[location] or convoluted_record[int,float]. So, even though the map structure is not even used in the function, I have to copy and paste this function for every map that I wish to load, since they all have different structures.
This function is actually already in ZLib -- but of course it's useless for updating maps that aren't string[familiar].
It's a pity I can't just use "aggregate" as the type for dest.
Possible workarounds I've thought of so far:
1) There may be a workaround Using cli_execute("ash etc etc"), because you could specify the map structure as a string, but I haven't been able to think of one that doesn't need to load the map more than once from disk. Also, how would the return value remain meaningful?
2) There may also be a workaround using an overlarge string[string,string,string,string,string,string,string] map as the parameter, to accommodate most possible record types. Haven't explored this avenue because it looks so unattractive.
3) A combination of the above two, where instead of a map parameter, the number of data points (strings) per line in the map is given as the second parameter. Then the map type can be specified without extra strings looked for using the cli_execute("ash blah") trick.
4) Is there any way to do this using ASH's "call"? I'm thinking not, but thought I'd ash. Er, ask.
Um, that's all I've got so far. How to handle the return value is tricky with all of these. It's a problem that's been nagging at me for a while now. Any help would be appreciated.
I use this function a lot to load maps from my Map Manager:
Code:
boolean load_current_map(string fname, string[string] dest) {
string curr = visit_url("http://zachbardon.com/mafiatools/autoupdate.php?f="+fname+"&act=getver");
file_to_map(fname+".txt",dest);
if (count(dest) == 0 || (curr != "" && get_property(fname+".txt") != curr)) {
print("Updating "+fname+".txt from '"+get_property(fname+".txt")+"' to '"+curr+"'...");
if (!file_to_map("http://zachbardon.com/mafiatools/autoupdate.php?f="+fname+"&act=getmap",dest) || count(dest) == 0) return false;
map_to_file(dest,fname+".txt");
set_property(fname+".txt",curr);
print("..."+fname+".txt updated.");
}
return true;
}
I would love to put this function in ZLib, where I could just have it once for all my scripts. Note that everything inside this function is completely portable. But the problem is that the map may be of any structure -- i.e. it's not always string[string], it may be familiar[location] or convoluted_record[int,float]. So, even though the map structure is not even used in the function, I have to copy and paste this function for every map that I wish to load, since they all have different structures.
This function is actually already in ZLib -- but of course it's useless for updating maps that aren't string[familiar].
It's a pity I can't just use "aggregate" as the type for dest.
Possible workarounds I've thought of so far:
1) There may be a workaround Using cli_execute("ash etc etc"), because you could specify the map structure as a string, but I haven't been able to think of one that doesn't need to load the map more than once from disk. Also, how would the return value remain meaningful?
2) There may also be a workaround using an overlarge string[string,string,string,string,string,string,string] map as the parameter, to accommodate most possible record types. Haven't explored this avenue because it looks so unattractive.
3) A combination of the above two, where instead of a map parameter, the number of data points (strings) per line in the map is given as the second parameter. Then the map type can be specified without extra strings looked for using the cli_execute("ash blah") trick.
4) Is there any way to do this using ASH's "call"? I'm thinking not, but thought I'd ash. Er, ask.
Um, that's all I've got so far. How to handle the return value is tricky with all of these. It's a problem that's been nagging at me for a while now. Any help would be appreciated.