Skip to main content

The "ds_struct_write" Function

Syntax#

ds_struct_write(id, [pretty]);
ArgumentTypeDescription
idstructThe struct to encode as a string
[pretty]booleanOptional: Enables or disables formatting the string with linebreaks and indentation

Description#

Converts a struct and its contents to a string, optionally with "pretty-print" to separate values by line with proper indenting.

caution

Note that only single values, arrays, strings, and sub-structs are interpreted by this function. Other data structures, like ds_map or ds_grid, are stored by reference only and will be written as a numerical index rather than their actual contents. To avoid this behavior, first use the respective ds_*_write function on these data structures so they will be included as strings which can be decoded later with ds_*_read.

Example#

var file = file_text_open_write("settings.json");
file_text_write_string(
file,
ds_struct_write(my_struct, true)
);
file_text_close(file);