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
+56-1
Original file line number
Diff line number
Diff line change
@@ -86,7 +86,7 @@ You can also reach Sandbox properties from the node.
86
86
87
87
:::warning
88
88
89
-
It is very tempting to assign an ELF program as the script to a Sandbox node. Don't do that. Calls you make to the Sandbox node will not go to the script first. The empty Sandbox will fail on random things and just appear confusing. Just make a regular Node and assign the ELF to that. You can use a Sandbox node, but don't set an ELF program as the script.
89
+
It is very tempting to assign an ELF program as the script to a regular Sandbox node. Don't do that. Calls you make to the Sandbox node will not go through the script instance. A script instance has a loaded Sandbox inside it, but the Sandbox node won't _unless you load it_, and then you have 2 instances, one of which you aren't using. An empty Sandbox will fail on random things and just appear confusing. Make a regular Node and assign the ELF to that.
90
90
91
91
:::
92
92
@@ -166,6 +166,56 @@ You can also load an ELF resource and use its content as a program. And, finally
166
166
If you want to create a program shared with many nodes, use `set_script(elf_resource)` which sets the ELF resource directly and references it. This method enables sandboxed properties.
167
167
168
168
169
+
## Sandbox creation summary
170
+
171
+
So, let's summarize the different methods:
172
+
173
+
1. Setting an ELF program as a script
174
+
175
+
The script method allows us to use other nodes, eg. a Node2D. Godot will call regular functions on the script, and so you can implement eg, `_process` in the program. Properties are exposed etc.
176
+
177
+
```py
178
+
var n = Node.new()
179
+
n.set_script(Sandbox_HelloWorld)
180
+
n.hello_world() # Public API methods work
181
+
```
182
+
183
+
2. Add a new Sandbox_HelloWorld using _Add Child Node_ in the editor
184
+
185
+
You should see the different types of available Sandbox-derivatives in the list under Sandbox. This is the most useful (and weirdest) form of Sandbox. It's automatically created from each ELF seen. It will give you auto-completion and generally easy access through GDScript.
186
+
187
+
Add a regular Node first and then add the custom sandbox under it. Then attach a GDScript to the node.
188
+
189
+
```py
190
+
var h = get_node("Sandbox_HelloWorld") as Sandbox_HelloWorld
191
+
h.hello_world()
192
+
```
193
+
194
+
3. Setting an ELF program on a Sandbox node
195
+
196
+
Here you won't get auto-completion but you can still call any method as before.
197
+
198
+
```py
199
+
var s = Sandbox.new()
200
+
s.set_program(Sandbox_HelloWorld)
201
+
#s.hello_world() # Public API methods DON'T work
202
+
s.vmcall("hello_world") # VMCall the function instead
203
+
```
204
+
205
+
4. Loading a program as a buffer on a Sandbox node
206
+
207
+
Same as above, you won't get auto-completion but you can still call any method as before.
208
+
209
+
```py
210
+
var s = Sandbox.new()
211
+
s.load_buffer(buffer)
212
+
#s.hello_world() # Public API methods DON'T work
213
+
s.vmcall("hello_world") # VMCall the function instead
214
+
```
215
+
216
+
The last two methods are mostly intended for UGC and modding.
217
+
218
+
169
219
## Sandbox API reference
170
220
171
221
The public API of the Sandbox node, which [originates from here](https://github.com/libriscv/godot-sandbox/blob/main/src/sandbox.h).
@@ -431,5 +481,10 @@ class Sandbox : public Node {
431
481
/// @param use_argument_names If true, use argument names with default values in the generated API. Increases the size of the generated API and the compilation time.
0 commit comments