Skip to content

Commit 6487d28

Browse files
committed
Add Sandbox auto-completion when used as script
1 parent ead76c1 commit 6487d28

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

docs/godot_intro/sandbox.md

+30
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,41 @@ Disadvantages:
7070
- Shared state between all instances requires per-object structures internally to manage individual object state
7171
- No control over lifetime of Sandbox
7272
- All limits and restrictions are shared
73+
- Harder to debug instance shared by many entities
74+
75+
![alt text](/img/intro/auto-complete.png)
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+
7387

7488
![attach signal](/img/sandbox/attach_signal.png)
7589

7690
It's possible to attach signals directly to a Node like you usually would do with GDScript when the script is directly embedded.
7791

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:
101+
```
102+
[ GDExtension::Sandbox <--> Instance ID:39678117514 ]
103+
[ GDExtension::Sandbox <--> Instance ID:39678117514 ]
104+
```
105+
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+
78108
## Dedicated Sandbox nodes
79109

80110
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`.

static/img/intro/auto-complete.png

53.5 KB
Loading

0 commit comments

Comments
 (0)