Enables/disables live reloading for a specific included file.
This can be used for live-updating game data, localization, or anything else.
path
is a relative path to the file (e.g. some.txt
, or GMLive/gmlive.html
).
You may go out of the included file directory using ../
to read other files
inside the project directory (e.g. ../notes/mynote/mynote.txt
), but not files outside
of the project directory.
callback
is a function/script that will be called whenever the file changes.
The function's first argument will be the new contents (more on this later)
and the second argument will be the relative path (as provided here).
Omit this argument or set it to undefined
to disable live reloading.
kind
is a string determining how to load the file. It can be one of the following:
-
"text"
: provides file contents as a string.
-
"buffer"
: provides file contents as a buffer.
Note that the buffer will be automatically deleted later so you should copy the data
from it somewhere as necessary.
-
"csv"
: provides file contents as a CSV grid (using load_csv
).
Similarly, the grid will be automatically deleted afterwards.
-
"json"
: provides file contents as a JSON value, provided that it's valid JSON.
-
"base64"
: provides file contents as a base64 string.
This is the format data is originally received in and is convenient if you intend
to decode it yourself as you please.
If kind
is not specified or is set to "auto"
, it will be auto-detected based on file extension:
-
.txt
➜ "text"
-
.json
➜ "json"
-
.bin
➜ "buffer"
-
.csv
➜ "csv"
-
.b64
, .base64
➜ "base64"
If the file extension is not recognized, an error is thrown.
Example (assuming that you have a test.txt
in your Included Files):
file_set_live("test.txt", function(_text, _path) {
show_debug_message(_path + " has been updated: " + _text);
});
With a file type override:
file_set_live("test.txt", function(_buf, _path) {
show_debug_message(_path + " is now " + buffer_get_size(_buf) + " bytes long");
}, "buffer");
Disabling live-reloading:
file_set_live("test.txt", undefined);