You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/godot_intro/sandbox.md
+30
Original file line number
Diff line number
Diff line change
@@ -70,11 +70,41 @@ Disadvantages:
70
70
- Shared state between all instances requires per-object structures internally to manage individual object state
71
71
- No control over lifetime of Sandbox
72
72
- All limits and restrictions are shared
73
+
- Harder to debug instance shared by many entities
74
+
75
+

76
+
77
+
In this case, the scene root is just a regular Node2D with a Sandbox ELF program as the script. Auto-completion works from nodes lower on the hierarchy, but be careful about how you access the parent node: `get_parent()` will give GDScript the information needed to get the methods from the underlying Sandbox program instance. We can see that test is a `int test(a: int, b: int)` function.
78
+
79
+
```py
80
+
func _ready() -> void:
81
+
var n = get_parent()
82
+
n.execution_timeout =0
83
+
```
84
+
85
+
You can also reach Sandbox properties from the node.
86
+
73
87
74
88

75
89
76
90
It's possible to attach signals directly to a Node like you usually would do with GDScript when the script is directly embedded.
77
91
92
+
93
+
Reaching the underlying Sandbox is possible, but requires both the script instance and the owning Node to look up the Sandbox:
94
+
```py
95
+
func _ready() -> void:
96
+
var n = get_parent()
97
+
var script = n.get_script() as ELFScript
98
+
print(script.get_sandbox_for(n))
99
+
```
100
+
Which correctly prints the same Sandbox twice for two instantiations of the scene:
Hence, it's shared by all instances of the current scene. Or more specifically, it's shared by all script instances which have the given Node as owner.
106
+
107
+
78
108
## Dedicated Sandbox nodes
79
109
80
110
When a dedicated Sandbox node is created, the program inside has the same lifetime as the node. Like the first paragraph we create a new Sandbox using the listed Sandbox nodes that show up as ELF programs are scanned. So, a typical node name can be `Sandbox_TestTest` if the ELF is stored in `test/test.elf`.
0 commit comments