Skip to reading
GDScript Programming & Godot

26. Gameplay actions and await

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView PDF page
Code example
func run() -> void:
    await AddInventory({"itemId": "key", "count": 1})
    await SetObjectVisible({"entityId": "key_pickup", "visible": false})
    await PlaySound({"assetId": "chime", "channel": "puzzle"})
    await ShowMessage({"text": "The key is in my bag.", "duration": 2})

All 206 normal shared actions are PascalCase methods on PCAScriptBase. They accept one options dictionary. Field keys keep their original spelling. You can also use await Action("ActionID",

Code example
options).

Awaiting an action waits for its runtime routine. It does not promise that every visible effect has finished. Starting music or most imported animations returns while playback continues. A camera blend or fade may wait, and some actions have a wait option.

The result depends on the action. It can be null, a Boolean, query data or a status dictionary. Native action calls do not gain PCA Script’s try/catch semantics. Check meaningful results and the resulting state when a failure needs recovery.

Page 35 of 378Permalink
Go to page