-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdynamoscript.gml
More file actions
64 lines (58 loc) · 3.38 KB
/
Copy pathdynamoscript.gml
File metadata and controls
64 lines (58 loc) · 3.38 KB
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
// Feather disable all
/// Sets up a script to watch for changes. If DYNAMO_AUTO_SCAN is set to <true> then watched
/// scripts will be scanned for changes automatically. You can check if a script has changed
/// by calling DynamoScriptChanged(), and the script can be loaded and its changes applied with
/// DynamoScriptLoad().
///
/// Because data is being stored in a script and *not* instead a function, the code inside a
/// script is executed on boot by the GameMaker runtime as you'd expect. This means that, unlike
/// file watchers, data represented inside a Dynamo script is immediately available.
///
/// There are many limitations to what can be done with Dynamo and scripts. It's best to think
/// about Dynamo scripts as being as complex as JSON but no further. It is possible to reference
/// basic numbers and strings (of course!) as well as being able to nest arrays and structs as
/// you would in JSON. You may also reference asset names and GameMaker constants. You cannot,
/// however, create functions inside Dynamo scripts. You can't use conditional branching or loops
/// or anything that controls programme "flow". Dynamo is also expecting all variables you're
/// defining in the script to be globals.
///
/// If you call DynamoScriptLoad() then the script will be loaded, and its changed applied,
/// whether there have been changes or not, and the callback provided when calling DynamoScript()
/// will be executed. The callback will be handed one arguments: the callback data provided when
/// calling DynamoScript().
///
/// If the <autoLoad> argument is set to <true> when calling DynamoScript() then the script will
/// automatically be loaded and applied whenever a change is detected, executing the callback as
/// though DynamoScriptLoad() had been called directly for the file.
///
/// Note that setting up a script watcher will not automatically execute the callback on boot.
/// If you want to execute the callback at the start of your game you'll need to call
/// DynamoScriptLoad() directly yourself.
///
/// @param script
/// @param autoLoad
/// @param [callback]
/// @param [callbackData]
function DynamoScript(_script, _autoLoad, _callback = undefined, _callbackData = undefined)
{
static __globalState = __DynamoState();
if (DYNAMO_RUNNING)
{
if (not is_numeric(_script)) __DynamoError("Illegal datatype passed for the script index (was ", typeof(_script), ")");
if (not script_exists(_script)) __DynamoError("Script with index ", _script, " doesn't exist");
if (is_numeric(_callback))
{
if (not script_exists(_callback)) __DynamoError("Callback script with index ", _callback, " doesn't exist");
}
else if (not is_method(_callback) && (_callback != undefined))
{
__DynamoError("Illegal datatype passed for the callback (was ", typeof(_callback), ")");
}
var _scriptName = script_get_name(_script);
if (variable_struct_exists(__globalState.__scriptStruct, _scriptName)) __DynamoError("Script \"", _scriptName, "\" is already being watched");
var _watcher = new __DynamoClassScript(_scriptName, DYNAMO_PROJECT_DIRECTORY + "scripts/" + string_lower(_scriptName) + "/" + string_lower(_scriptName) + ".gml");
_watcher.__autoLoad = _autoLoad;
_watcher.__callback = _callback;
_watcher.__callbackData = _callbackData;
}
}