22. Call the same actions from a script
A text script is useful when a short conditional operation is clearer in code. The supported scripting languages share the action names, while each language keeps its own syntax. The following is a complete GDScript example for the editor's standard PCA script base.
func run(_context: Dictionary = {}) -> Variant:
await ChangeVariable({
"name": "powered", "operation": "set", "value": true
})
await PlaySound({"assetId": "chime", "channel": "puzzle"})
await ShowMessage({"text": "The signal is on.",
"duration": 2.2})
return true1. Create a GDScript record and give it a stable ID, such as power_signal.
2. Enter the code, validate it and click Apply Changes. Save the project.
3. On the lever or GUI event, choose Run Visual Script and select that text script.
4. Test the call through its real event, not just the editor's Run Script button.
Await means the caller waits for the action routine to return. It cannot force an action to wait for something the routine only starts. Play Sound starts playback; Show Message waits for its presentation routine. Animation timing needs the same distinction.
GDScript records without an explicit extends line receive PCA's standard script base. A custom base must inherit the PCA base to use these helpers. Godot's self still means the script instance; this means the calling game record.
