Loading...
Loading...
Write idiomatic GDScript for Godot 4.x: static typing, the node lifecycle (_ready/_process/_physics_process), @export/@onready/@tool annotations, signals, and await for asynchronous flow. Use when editing .gd scripts in a Godot project (project.godot), writing or debugging GDScript, or porting 3.x GDScript to 4.x (func signatures, yield -> await, export -> @export).
npx skill4agent add gamedev-skills/awesome-gamedev-agent-skills godot-gdscript.gd@export@onreadygodot-nodes-scenesgodot-signals-groupsgodot-csharpvar hp: int = 10func add(a: int, b: int) -> int::=_ready()_process(delta)_physics_process(delta)@onready_init()@exportawaitextends Node2D
class_name Spinner # registers a global type usable in other scripts
@export var speed: float = 90.0 # editable in the Inspector (degrees/sec)
@export_range(0, 10, 0.5) var wobble := 2.0
@onready var sprite: Sprite2D = $Sprite2D # resolved when the node enters the tree
func _ready() -> void:
# Runs once, after children are ready. Safe to touch $Sprite2D here.
sprite.modulate = Color.AQUA
func _process(delta: float) -> void:
# delta is seconds since last frame; multiply rates by it for FPS independence.
rotation_degrees += speed * deltaextends Node
signal health_changed(current: int, maximum: int) # typed signal params
var health := 100
func take_damage(amount: int) -> void:
health = max(health - amount, 0)
health_changed.emit(health, 100) # 4.x: emit as a method on the signal
func _ready() -> void:
# 4.x: connect with a Callable, not a string method name.
health_changed.connect(_on_health_changed)
func _on_health_changed(current: int, maximum: int) -> void:
print("HP: %d/%d" % [current, maximum])func flash_then_continue() -> void:
modulate = Color.RED
await get_tree().create_timer(0.2).timeout # resume after 0.2s
modulate = Color.WHITE
# await any signal: var result = await some_node.some_signalvar enemies: Array[Node] = [] # typed array
func cull_dead() -> void:
enemies = enemies.filter(func(e): return e.is_inside_tree())
func get_first_name(d: Dictionary) -> String:
return d.get("name", "unknown") # default avoids missing-key errorsemit_signal("x")x.emit(...)connect("x", self, "_on_x")x.connect(_on_x)yield(obj, "sig")await obj.sigexport var@export varonready@onreadytool@toolremotemaster@rpc(...)@onready$NodePath_init()_ready()@onready5 / 2 == 25.0 / 2float_process_physics_processmove_and_slide()_physics_process(delta)_processclass_namereferences/annotations-and-typing.mdgodot-nodes-scenesgodot-signals-groupsgodot-resourcesResourcegodot-csharp