I thought that a file like this:The problem is that it doesn't properly go through all the dimensions in the map to print them all. That's the same problem I'm having with writing a patch. Well, that and that I'm extremely inexperienced with java.
Giant's Castle Disco Bandit 5
Giant's Castle Pastamancer 10
Hobopolis Town Square Sauceror 20
Outskirts of The Knob Pastamancer 10
temp[ "Giant's Castle" ] = "Disco Bandit 5"
file-to-map is a built-in function.
Here is a function that takes a map that was saved into a temporary file and turns it into a string. The parameters that are passed to it are the name of the temporary file that contains the map and a number indicating how many fields are in the map.Since you'd always (at least, I can't think of a situation in which you wouldn't) know the amount of dimensions your aggregate would have at the time of writing the code, couldn't you pass that number as an argument? It'd still probably be murder writing the code to -handle- that information, but I'm sure someone clever could find a way to construct the string[string, string, ...] with that number.
string file_to_string( string file, int dim )
{
if ( file == "" || dim < 2 )
{
print( "usage: print_map( string file, int dim ) - file cannot be empty, dim must be greater than 1", "red" );
return "";
}
string command;
command += "ashq " ;
command += "string str; " ;
command += "string [ ";
for i from 1 to (dim - 1)
{
command += "string";
if( i < (dim - 1) ) command += ", ";
}
command += " ] print_map; ";
command += "file_to_map( '" + file + "', print_map ); ";
command += "foreach ";
for i from 1 to dim
{
command += "str" + i;
if( i < dim ) command += ", ";
}
command += " in print_map ";
command += "str += ";
for i from 1 to dim
{
command += "str" + i + " ";
if( i < dim ) command += "+ '=>' + ";
}
command += "+ '||';";
command += "string [ int ] save_map; ";
command += "save_map[ 0 ] = str; ";
command += "map_to_file( save_map, '" + file + "' );";
cli_execute( command );
string [ int ] load_map;
file_to_map( file, load_map );
return load_map[ 0 ];
}
int [ location, class, item ] temp;
temp[ $location[ Giant's Castle ], $class[ Disco Bandit ], $item[ Disco Banjo ] ] = 5 ;
temp[ $location[ Giant's Castle ], $class[ Pastamancer ], $item[ Shagadelic Disco Banjo ] ] = 10 ;
temp[ $location[ Outskirts of The Knob ], $class[ Pastamancer ], $item[ disco mask ] ] = 10 ;
temp[ $location[ Hobopolis Town Square ], $class[ Sauceror ], $item[ disco mask ] ] = 20 ;
map_to_file( temp, "temp.txt" );
print( file_to_string( "temp.txt", 4 ) );
Giant's Castle=>Disco Bandit=>Disco Banjo=>5||Giant's Castle=>Pastamancer=>Shagadelic Disco Banjo=>10||Hobopolis Town Square=>Sauceror=>disco mask=>20||Outskirts of The Knob=>Pastamancer=>disco mask=>10||
print( file_to_string( "temp.txt", 2 ) );
Giant's Castle=>Pastamancer||Hobopolis Town Square=>Sauceror||Outskirts of The Knob=>Pastamancer||
string str;
string [ string, string, string ] print_map;
file_to_map( 'temp.txt', print_map );
foreach str1, str2, str3, str4 in print_map
str += str1 + '=>' + str2 + '=>' + str3 + '=>' + str4 + '||';
string [ int ] save_map;
save_map[ 0 ] = str;
map_to_file( save_map, 'temp.txt' );
string file_to_string( string file, int dim )
{
if ( file == "" || dim < 2 )
{
print( "usage: print_map( string file, int dim ) - file cannot be empty, dim must be greater than 1", "red" );
return "";
}
string command;
command += "ashq " ;
command += "string str; " ;
command += "string [ ";
for i from 1 to (dim - 1)
{
command += "string";
if( i < (dim - 1) ) command += ", ";
}
command += " ] print_map; ";
command += "file_to_map( '" + file + "', print_map ); ";
command += "foreach ";
for i from 1 to dim
{
command += "str" + i;
if( i < dim ) command += ", ";
}
command += " in print_map ";
command += "str += ";
for i from 1 to dim
{
command += "str" + i + " ";
if( i < dim ) command += "+ '\\t' + ";
}
command += "+ '\\n';";
command += "set_property( 'file2string', str ); ";
cli_execute( command );
return get_property( 'file2string' );
}
int [ location, class, item ] temp;
temp[ $location[ Giant's Castle ], $class[ Disco Bandit ], $item[ Disco Banjo ] ] = 5 ;
temp[ $location[ Giant's Castle ], $class[ Pastamancer ], $item[ Shagadelic Disco Banjo ] ] = 10 ;
temp[ $location[ Outskirts of The Knob ], $class[ Pastamancer ], $item[ disco mask ] ] = 10 ;
temp[ $location[ Hobopolis Town Square ], $class[ Sauceror ], $item[ disco mask ] ] = 20 ;
map_to_file( temp, "temp.txt" );
print( file_to_string( "temp.txt", 4 ) );
> call test.ash
file2string => Giant's Castle Disco Bandit Disco Banjo 5
Giant's Castle Pastamancer Shagadelic Disco Banjo 10
Hobopolis Town Square Sauceror disco mask 20
Outskirts of The Knob Pastamancer disco mask 10
Giant's Castle Disco Bandit Disco Banjo 5Giant's Castle Pastamancer Shagadelic Disco Banjo 10Hobopolis Town Square Sauceror disco mask 20Outskirts of The Knob Pastamancer disco mask 10
file2string=Giant's Castle\tDisco Bandit\tDisco Banjo\t5\nGiant's Castle\tPastamancer\tShagadelic Disco Banjo\t10\nHobopolis Town Square\tSauceror\tdisco mask\t20\nOutskirts of The Knob\tPastamancer\tdisco mask\t10
record {
int num;
item itm;
class cls;
} [ int ] test_rec;
test_rec[ 0 ].num = 1;
test_rec[ 0 ].itm = $item[ big rock ];
test_rec[ 0 ].cls = $class[ disco bandit ];
test_rec[ 1 ].num = 2;
test_rec[ 1 ].itm = $item[ disco banjo ];
test_rec[ 1 ].cls = $class[ pastamancer ];
0 1 big rock Disco Bandit
1 2 Disco Banjo Pastamancer
map_to_file( test_rec, "temp.txt" );
file_to_string( "temp.txt", 4 );
file2string=0\t1\tbig rock\tDisco Bandit\n1\t2\tDisco Banjo\tPastamancer
0 num 1
0 itm big rock
0 cls Disco Bandit
1 num 2
1 itm Disco Banjo
1 cls Pastamancer
Hmm... too late at night (5am my time) to fully analyze that, but for reference what I'm looking for is a format IDENTICAL to the contents of map_to_file()'s output, so I can upload it to a remote server via a mafia script & a small server script.
Edit: further analyzed, wouldn't work for what I'm doing, as some records have fields which are themselves aggregates.
0 Hello
As for aggregates of records of aggregates...
That depends on how file_to_map works. I know it ignores information in excess of the map being retrieved, but does it fill defaults into fields that are omitted in the file?
That is, would fileGet stored to string[string, string] as ["Hello",""]=>"0"?Code:0 Hello
If so, then you'd only need to know the maximum depth from the starting aggregate to the final aggregate (counting the record itself as 1 field of depth).
It doesn't really matter what your initial map contains, as long as you know how many fields you will have in the file that is written by map_to_file().Edit: further analyzed, wouldn't work for what I'm doing, as some records have fields which are themselves aggregates.
record {
int num;
item itm;
int [ item ] agr;
} [ int ] test_rec;
test_rec[ 0 ].num = 1;
test_rec[ 0 ].itm = $item[ big rock ];
test_rec[ 0 ].agr[ $item[ seal tooth ] ] = 99;
test_rec[ 0 ].agr[ $item[ hot butter roll ] ] = 99;
test_rec[ 1 ].num = 2;
test_rec[ 1 ].itm = $item[ disco banjo ];
test_rec[ 1 ].agr[ $item[ seal tooth ] ] = 999;
test_rec[ 1 ].agr[ $item[ hot butter roll ] ] = 999;
map_to_file( test_rec, "temp.txt" );
0 num 1
0 itm big rock
0 agr hot buttered roll 99
0 agr seal tooth 99
1 num 2
1 itm Disco Banjo
1 agr hot buttered roll 999
1 agr seal tooth 999
file2string=0\tagr\thot buttered roll\t99\n0\tagr\tseal tooth\t99\n0\titm\tbig rock\t\n0\tnum\t1\t\n1\tagr\thot buttered roll\t999\n1\tagr\tseal tooth\t999\n1\titm\tDisco Banjo\t\n1\tnum\t2
I know virtually nothing about text files ^^Looking at his slyz's code (go slyz!) it's only a small change to make the string information identical to the file in terms of display.
It does fill defaults, and the default string should be simply "". As you can see above, if your data file has a line with 4 fields and another line with 3 fields, the "" key will be added.That depends on how file_to_map works. I know it ignores information in excess of the map being retrieved, but does it fill defaults into fields that are omitted in the file?
string [ int ] test;
test[ 0 ] = "hello";
map_to_file( test, "temp.txt" );
file_to_string( "temp.txt", 6 );
file2string=0\thello\tnone\tnone\tnone
> ash to_string( $item[none] );
Returned: none
string file_to_string( string file, int dim )
{
if ( file == "" || dim < 2 )
{
print( "usage: print_map( string file, int dim ) - file cannot be empty, dim must be greater than 1", "red" );
return "" ;
}
string command;
command += "ashq " ;
command += "string str; " ;
command += "string [ " ;
for i from 1 to (dim - 1)
{
command += "string" ;
if( i < (dim - 1) ) command += ", " ;
}
command += " ] print_map; " ;
command += "file_to_map( '" + file + "', print_map ); " ;
command += "foreach " ;
for i from 1 to dim
{
command += "str" + i ;
if( i < dim ) command += ", " ;
}
command += " in print_map " ;
command += " { " ;
for i from 1 to dim
{
command += "if( str" + i + " == 'none' ) { str +='\\n'; continue; } " ;
command += "else str += str" + i + " " ;
if( i < dim ) command += "+ '\\t'; " ;
else command += "+ '\\n'; " ;
}
command += " } " ;
command += "set_property( 'file2string', str ); " ;
cli_execute( command );
//print( command );
return get_property( 'file2string' );
}
string [ int ] test;
test[ 0 ] = "hello";
map_to_file( test, "temp.txt" );
file_to_string( "temp.txt", 6 );
file2string=0\thello
I know virtually nothing about text files ^^
What change would the string need? I only used \t for tabs and \n for end-of-lines, but that can be easily changed, especially if the string is meant to be passed to a site.