Skip to reading
GDScript Programming & Godot

2. Create and run your first GDScript

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 illustrations

1. Open a project. In the Adventure Database, add a native Script record. Select it to open the GDScript workspace.

2. Use an ID such as hello_gd and a readable name such as First GDScript. Keep script IDs unique across languages.

3. Enter the source below. Click Validate, then Apply Changes. Save the project.

4. Start a Test Scene or Play session. Use Run Script to execute the record against that runtime. A gameplay call needs a running game.

Code example
func run(call_context: Dictionary = {}) -> void:
    Log("GDScript is running.")
    await ShowMessage({"text": "Welcome to the workshop.", "duration": 2})

Figure 2. The native GDScript workspace shows source, event subscriptions, the global-instance option and the script toolbar.

You can omit an extends line in a PCA script record. PCA then adds its PCAScriptBase, which inherits Godot’s Node class. You still have GDScript and Godot functionality, with the PCA helpers available as inherited methods.

Page 10 of 378Permalink
Go to page