Skip to reading
GDScript Programming & Godot

23. Self, this and the player

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() -> bool:
    if this == null:
        Warn("This interaction needs a caller.")
        return false
    Log("Caller ID: " + str(this.Get("id", "")))
    return true

self is the Godot script instance. this is PCA’s caller proxy when a caller is available. player is the active character’s PCA record proxy, refreshed at the start of a call. None of these automatically means the selected editor object.

A proxy describes a PCA record and routes supported changes. It is not the rendered Node3D. Adding a Timer to self creates a Godot child of the script. Changing this.visible addresses the caller’s record/runtime route instead.

A nested call normally preserves caller context. A direct Run or a global event may have no caller, so reusable interaction code must tolerate null. If the active player can change during an awaited sequence, capture the intended character ID before waiting.

Page 32 of 378Permalink
Go to page