/
ds_map_save.gml
69 lines (64 loc) · 2.28 KB
/
ds_map_save.gml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#define ds_map_save
/// ds_map_save(id, file [,delim])
//
// Saves the contents of a given grid
// data structure into a file.
//
// id map data structure, real
// file file name, string
// delim delimiter used between elements, optional
// 0 = Carriage Return (default)
// 1 = Comma (for CSV files)
// 2 = Semicolon
// other = a string of your choice
//
/// GMLscripts.com/license
{
var FileOut, NextKey, i;
FileOut = file_text_open_write(argument1);
if ( ds_map_size(argument0) > 0 ) {
NextKey = ds_map_find_first(argument0);
file_text_write_string(FileOut,string(NextKey)+', ');
file_text_write_string(FileOut,string(ds_map_find_value(argument0,NextKey)));
NextKey = ds_map_find_next(argument0,NextKey);
// Define the format to use
switch (argument2) {
case 0:
file_text_writeln(FileOut);
break;
case 1:
file_text_write_string(FileOut,',');
break;
case 2:
file_text_write_string(FileOut,';');
break;
default:
file_text_write_string(FileOut,string(argument2));
break;
}
if ( ds_map_size(argument0) > 1 ) {
for ( i = 1; i < ds_map_size(argument0); i += 1 ) {
file_text_write_string(FileOut,string(NextKey)+', ');
file_text_write_string(FileOut,string(ds_map_find_value(argument0,NextKey)));
NextKey = ds_map_find_next(argument0,NextKey);
// Define the format to use
switch (argument2) {
case 0:
file_text_writeln(FileOut);
break;
case 1:
file_text_write_string(FileOut,',');
break;
case 2:
file_text_write_string(FileOut,';');
break;
default:
file_text_write_string(FileOut,string(argument2));
break;
}
}
}
}
file_text_close(FileOut);
return 0;
}