[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6KR9AGK8H6WA03PFKQ5PBKD":3,"skill-same:01M6KR9AGK8H6WA03PFKQ5PBKD":90},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":36,"linkOnly":37,"markdownContent":38,"markdownBody":39,"frontMatter":40,"refName":41,"commitSha":42,"skillDirectory":43,"forksCount":44,"repositoryHtmlUrl":45,"repositoryHomepageUrl":6,"ownerHtmlUrl":46,"ownerBlogUrl":47,"ownerDescription":48,"updatedAt":49,"install":50,"resources":63},"01M6KR9AGK8H6WA03PFKQ5PBKD","gdscript-patterns",null,"Use when writing GDScript — static typing, await\u002Fcoroutines, lambdas, match patterns, export annotations, inner classes, and common idioms","jame581\u002FGodotPrompter","jame581","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F21112138?v=4","01M6KR3KEQ9Z30WVJRR2E2ZVXE","Jan Mesarč","01M6KR3KJVRMPDSMASQPBCBVK3",964,"MIT","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fgdscript-patterns\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35],"gdscript patterns","patterns","gdscript","when","idioms","match","use","coroutines","inner","static typing","await","annotations","export","common","writing","static","typing","2026-11-10 10:12:30",false,"---\nname: gdscript-patterns\ndescription: Use when writing GDScript — static typing, await\u002Fcoroutines, lambdas, match patterns, export annotations, inner classes, and common idioms\n---\n\n# GDScript Patterns in Godot 4.3+\n\nAll examples target Godot 4.3+ with no deprecated APIs.\n\n> **Related skills:** **gdscript-advanced** for production-grade depth (performance idioms, metaprogramming, @tool lifecycle, profiler-driven idioms), **godot-code-review** for style rules and anti-patterns, **csharp-godot** for GDScript-to-C# translation, **state-machine** for state patterns, **event-bus** for signal architecture.\n\n> **Note:** This skill is GDScript-specific by design. For C# patterns, see **csharp-godot** and **csharp-signals**.\n\n---\n\n## 1. Static Typing\n\n### Type Hints\n\nAlways add type hints — they catch bugs at parse time, improve autocomplete, and boost performance.\n\n```gdscript\n# Variables\nvar health: int = 100\nvar speed: float = 200.0\nvar player_name: String = \"Hero\"\nvar direction: Vector2 = Vector2.ZERO\n\n# Constants\nconst MAX_HEALTH: int = 100\nconst GRAVITY: float = 980.0\n\n# Functions — parameters and return type\nfunc take_damage(amount: int) -> void:\n    health -= amount\n\nfunc get_direction() -> Vector2:\n    return Input.get_vector(\"ui_left\", \"ui_right\", \"ui_up\", \"ui_down\")\n\n# Inferred typing with :=\nvar pos := Vector2(100, 200)     # inferred as Vector2\nvar items := []                  # inferred as Array (untyped)\nvar count := 0                   # inferred as int\n```\n\n### Typed Collections\n\n```gdscript\n# Typed arrays — only accepts the specified type\nvar enemies: Array[Enemy] = []\nvar scores: Array[int] = [10, 20, 30]\nvar names: Array[String] = [\"Alice\", \"Bob\"]\n\n# Typed dictionaries (Godot 4.4+)\nvar inventory: Dictionary[String, int] = {\"sword\": 1, \"potion\": 5}\n\n# Typed loop variable\nfor enemy: Enemy in enemies:\n    enemy.take_damage(10)\n\n# Typed array methods work with type safety\nvar filtered: Array[Enemy] = enemies.filter(func(e: Enemy) -> bool: return e.health > 0)\n```\n\n### Casting with `as` and `is`\n\n```gdscript\n# 'is' — type check (returns bool)\nfunc _on_body_entered(body: Node2D) -> void:\n    if body is Player:\n        var player: Player = body as Player\n        player.take_damage(10)\n\n# 'as' — cast (returns null on failure, no error)\nvar sprite := get_node(\"Sprite\") as Sprite2D\nif sprite:\n    sprite.modulate = Color.RED\n\n# Prefer 'is' check + cast over bare 'as' to avoid null surprises\n```\n\n### Enabling Strict Typing Warnings\n\nIn **Project > Project Settings > Debug > GDScript**:\n\n| Warning | Effect |\n|-------------------------|---------------------------------------------|\n| `UNTYPED_DECLARATION` | Warns on any untyped variable\u002Fparameter |\n| `INFERRED_DECLARATION` | Warns on `:=` (prefers explicit types) |\n| `UNSAFE_CAST` | Warns when an untyped (`Variant`) value is cast to a type |\n| `UNSAFE_CALL_ARGUMENT` | Warns when an argument's type is a supertype of the parameter's (`Node` into a `Node2D` parameter) |\n| `ONREADY_WITH_CAST` (Godot 4.8+) | Warns when an `@onready` initializer casts a `$Node` literal (`$Label as Label`), which may assign `null` |\n\n> Set warnings to **Error** for strict enforcement in team projects.\n\n### Typed Return Inheritance in Overrides\n\n> ⚠️ **Changed in Godot 4.7:** Methods that override a method with a typed return now inherit the return type, so an override without an explicit `return` statement becomes an error. Add `return null` (or a typed return value) at the end of the override. See the [4.7 migration guide](https:\u002F\u002Fdocs.godotengine.org\u002Fen\u002Flatest\u002Ftutorials\u002Fmigrating\u002Fupgrading_to_godot_4.7.html).\n\n```gdscript\nclass Enemy:\n    var weapon: Node\n    func get_weapon() -> Node:\n        return weapon\n\nclass UnarmedEnemy extends Enemy:\n    func get_weapon():  # 4.7+: inherits -> Node from Enemy\n        return null     # explicit return now required — omitting it is an error\n```\n\n---\n\n## 2. Await & Coroutines\n\n### Awaiting Signals\n\n`await` pauses the function until a signal fires, then resumes. The function becomes a coroutine.\n\n```gdscript\nfunc death_sequence() -> void:\n    $AnimationPlayer.play(\"death\")\n    await $AnimationPlayer.animation_finished  # pauses here\n\n    $Sprite2D.visible = false\n    await get_tree().create_timer(1.0).timeout  # wait 1 second\n\n    queue_free()\n```\n\n### Awaiting with Return Values\n\n```gdscript\n# Signal that passes data\nsignal dialogue_choice_made(choice: int)\n\nfunc show_dialogue(options: Array[String]) -> int:\n    # ... display UI ...\n    var choice: int = await dialogue_choice_made\n    return choice\n\n# Caller:\nfunc _on_npc_interact() -> void:\n    var result := await show_dialogue([\"Yes\", \"No\"])\n    if result == 0:\n        print(\"Player said yes\")\n```\n\n### Timer Patterns\n\n```gdscript\n# One-shot delay\nawait get_tree().create_timer(0.5).timeout\n\n# Repeating with await (simple but blocks the function)\nfor i in 5:\n    do_something()\n    await get_tree().create_timer(0.2).timeout\n\n# Non-blocking timer — use SceneTreeTimer or Tween instead\nget_tree().create_timer(2.0).timeout.connect(_on_delayed_action)\n```\n\n### Coroutine Safety\n\n```gdscript\n# DANGER: `target` may be freed while this coroutine waits\nfunc unsafe_coroutine(target: Node2D) -> void:\n    await get_tree().create_timer(5.0).timeout\n    target.position = Vector2.ZERO  # error: previously freed instance\n\n# SAFE: re-check other objects after every await\nfunc safe_coroutine(target: Node2D) -> void:\n    await get_tree().create_timer(5.0).timeout\n    if not is_instance_valid(target):\n        return\n    target.position = Vector2.ZERO\n```\n\nA freed node's own coroutine never resumes, so `is_instance_valid(self)` after `await` guards nothing.\n\n---\n\n## 3. Lambda Functions\n\nLambdas are inline anonymous functions for callbacks, sorting, and filtering, called with `.call()`. The reference covers single- and multi-line syntax, inline signal connections including `CONNECT_ONE_SHOT`, `Array` methods (`filter`, `map`, `reduce`, `any`, `all`, `sort_custom`), and closures, where locals are captured by value.\n\n> See [references\u002Flambda-functions.md](references\u002Flambda-functions.md) for the syntax, signal, `Array` method, and closure examples.\n\n---\n\n## 4. Match \u002F Pattern Matching\n\nGDScript's `match` is like `switch` but with pattern support.\n\n### Basic Match\n\n```gdscript\nmatch state:\n    State.IDLE:\n        play_idle()\n    State.RUNNING:\n        play_run()\n    State.JUMPING, State.FALLING:  # multiple patterns\n        play_air()\n    _:  # default (wildcard)\n        push_warning(\"Unknown state: %s\" % state)\n```\n\n### Pattern Types\n\n```gdscript\n# Literal patterns\nmatch value:\n    42:\n        print(\"The answer\")\n    \"hello\":\n        print(\"Greeting\")\n    true:\n        print(\"Boolean true\")\n\n# Binding pattern — captures value into a variable\nmatch command:\n    [\"move\", var direction]:\n        move(direction)\n    [\"attack\", var target, var damage]:\n        attack(target, damage)\n\n# Array pattern\nmatch input:\n    [1, 2, 3]:\n        print(\"Exact match\")\n    [1, ..]:\n        print(\"Starts with 1\")\n    [var first, _, var last]:\n        print(\"First: %s, Last: %s\" % [first, last])\n\n# Dictionary pattern\nmatch event:\n    {\"type\": \"damage\", \"amount\": var amt}:\n        take_damage(amt)\n    {\"type\": \"heal\", \"amount\": var amt}:\n        heal(amt)\n\n# Nested condition inside a branch\nmatch enemy_type:\n    \"boss\":\n        if health \u003C 50:\n            enter_rage_mode()\n        else:\n            normal_attack()\n```\n\n---\n\n## 5. Export Annotations\n\n`@export` exposes a variable to the Inspector. Hint variants (`@export_range`, `@export_enum`, `@export_file`) constrain editor input. Use `@export_group` and `@export_subgroup` to organize. Node and Resource exports use NodePath \u002F typed Resource references.\n\n> See [references\u002Fexport-annotations.md](references\u002Fexport-annotations.md) for the full export annotation catalog (basic exports, range\u002Fhint variants, groups, node and Resource exports).\n\n---\n\n## 6. Inner Classes & class_name\n\n### class_name\n\nRegister a script as a global class name — available everywhere without `preload`.\n\n```gdscript\n# item_data.gd\nclass_name ItemData\nextends Resource\n\n@export var name: String\n@export var icon: Texture2D\n@export var value: int\n\n# Now usable anywhere:\n# var item: ItemData = ItemData.new()\n# var items: Array[ItemData] = []\n```\n\n### Inner Classes\n\n```gdscript\n# Define a class inside another script\nclass HitResult:\n    var damage: int\n    var critical: bool\n    var knockback: Vector2\n\n    func _init(dmg: int, crit: bool, kb: Vector2 = Vector2.ZERO) -> void:\n        damage = dmg\n        critical = crit\n        knockback = kb\n\n# Usage\nfunc calculate_hit() -> HitResult:\n    var crit := randf() \u003C 0.2\n    var dmg := 10 * (2 if crit else 1)\n    return HitResult.new(dmg, crit, Vector2.RIGHT * 50)\n```\n\n---\n\n## 7. super() in Virtual Methods\n\nWhen you override a virtual method that the engine calls (`_ready`, `_process`, `_input`, etc.) and your parent class also implements it, call `super()` to chain the parent's behavior. Forgetting to call `super._ready()` is the most common cause of \"my base class init didn't run\" bugs.\n\n> See [references\u002Fsuper-in-virtual-methods.md](references\u002Fsuper-in-virtual-methods.md) for the full pattern (problem \u002F fix), the C# `base.X()` equivalent, and a catalog of bugs from missing super calls.\n\n---\n\n## 8. Common Idioms\n\nThe recurring small patterns: ternary expressions (`value if cond else other`), printf-style string formatting (`\"%s %d\" % [a, b]`), null\u002Fempty checks (`is_instance_valid` vs `!= null`, empty Array\u002FString checks), Dictionary access (`get(key, default)`), Array operations (`Array.has`, `Array.find`, `Array.has_all`), setget via `set` and `get` accessors.\n\n> See [references\u002Fcommon-idioms.md](references\u002Fcommon-idioms.md) for full code examples of each idiom.\n\n---\n\n## 9. Annotations Reference\n\n| Annotation | Purpose |\n|-----------------------|--------------------------------------------|\n| `@export` | Expose variable in Inspector |\n| `@export_range` | Numeric with slider |\n| `@export_enum` | Dropdown from string list |\n| `@export_file` | File path picker |\n| `@export_dir` | Directory picker |\n| `@export_multiline` | Multi-line text box |\n| `@export_group` | Group heading in Inspector |\n| `@export_subgroup` | Subgroup heading |\n| `@export_category` | Category divider |\n| `@onready` | Initialize when the node is ready, just before its `_ready()` body runs |\n| `@tool` | Run script in editor |\n| `@icon` | Custom icon for the script |\n| `@warning_ignore` | Suppress specific warning on next line |\n| `@static_unload` | Allow static variables to be freed |\n\n---\n\n## 10. Common Pitfalls\n\n| Symptom | Cause | Fix |\n|---------------------------------------|----------------------------------------------|------------------------------------------------------------------|\n| `as` cast silently returns `null` | Type mismatch — `as` doesn't error | Use `is` check first, then cast |\n| Await never resumes | Signal never emitted, or this node was freed (coroutine dropped) | Check the condition before awaiting; race slow signals against a timer |\n| Lambda's change to a variable is lost | Locals are captured by value | Keep shared state in a member, `Array` or `Dictionary` |\n| `UNTYPED_DECLARATION` warnings flood | Warning enabled but codebase isn't typed | Type incrementally; use `@warning_ignore` for legacy code |\n| Typed array assignment fails | A value that is a plain `Array` at runtime (a variable holding one, or the result of `map()` \u002F `filter()`) or an `Array[Subclass]` assigned to an `Array[Type]` variable (no covariance; subclass *elements* are accepted) | Declare it typed from the start, or `typed.assign(other)` |\n| `@onready` is `null` | Accessed before `_ready()` runs | Never access `@onready` vars in `_init()` or variable declarations |\n| Match doesn't enter any branch | No matching pattern and no `_:` wildcard | Always add `_:` default branch |\n| `class_name` conflict | Two scripts with same `class_name` | Use unique names; check for duplicates in Project |\n| Export group applies to wrong vars | Group scope continues until next group | Add a new `@export_group(\"\")` to end the group scope |\n| Parent `_ready()` logic doesn't run in child | Missing `super()` call in child's `_ready()` | Add `super()` as first line; see Section 7 |\n| `type_exists()` flagged as deprecated | Deprecated in Godot 4.7 | Use `ClassDB.class_exists()` instead |\n\n> ⚠️ **Changed in Godot 4.7:** The global `type_exists()` function is deprecated — replace `type_exists(\"Sprite2D\")` with `ClassDB.class_exists(\"Sprite2D\")`. See [GH-116899](https:\u002F\u002Fgithub.com\u002Fgodotengine\u002Fgodot\u002Fpull\u002F116899).\n\n---\n\n## 11. Variadic Functions (Godot 4.5+)\n\nGodot 4.5 added trailing-argument arrays via `...args`. The args are collected into an `Array`. Useful for printf-style helpers and flexible APIs without overloads.\n\n> See [references\u002Fvariadic-functions.md](references\u002Fvariadic-functions.md) for the full syntax, common patterns, and notes on when to prefer overloads.\n\n---\n\n## 12. Abstract Classes and Methods (Godot 4.5+)\n\nThe `@abstract` annotation prevents direct instantiation of a class and forces subclasses to implement any `@abstract`-annotated method (similar to C#'s `abstract` keyword).\n\n> See [references\u002Fabstract-classes.md](references\u002Fabstract-classes.md) for full base-class patterns and subclass implementation rules.\n\n---\n\n## 13. Implementation Checklist\n\n- [ ] All variables, parameters, and return types have explicit type hints\n- [ ] Typed arrays (`Array[Type]`) are used instead of untyped `Array` where possible\n- [ ] Other nodes used after an `await` are re-checked with `is_instance_valid()` (`self` needs no check)\n- [ ] Lambdas connected to signals are simple — complex logic goes in named methods\n- [ ] `match` statements include a `_:` default branch\n- [ ] `@export` variables use appropriate hints (`@export_range`, `@export_enum`, etc.)\n- [ ] `@export_group` organizes Inspector properties into logical sections\n- [ ] `class_name` is only used for scripts that need global visibility\n- [ ] `is` type check precedes `as` cast when the type isn't guaranteed\n- [ ] Properties with setters validate and clamp values\n- [ ] Overridden virtual methods call `super()` when extending non-built-in base classes\n- [ ] Variadic functions (`...args`) used when the number of trailing arguments is open-ended (Godot 4.5+)\n- [ ] Base classes that must not be instantiated use `@abstract`; required methods use `@abstract func` (Godot 4.5+)\n","# GDScript Patterns in Godot 4.3+\n\nAll examples target Godot 4.3+ with no deprecated APIs.\n\n> **Related skills:** **gdscript-advanced** for production-grade depth (performance idioms, metaprogramming, @tool lifecycle, profiler-driven idioms), **godot-code-review** for style rules and anti-patterns, **csharp-godot** for GDScript-to-C# translation, **state-machine** for state patterns, **event-bus** for signal architecture.\n\n> **Note:** This skill is GDScript-specific by design. For C# patterns, see **csharp-godot** and **csharp-signals**.\n\n---\n\n## 1. Static Typing\n\n### Type Hints\n\nAlways add type hints — they catch bugs at parse time, improve autocomplete, and boost performance.\n\n```gdscript\n# Variables\nvar health: int = 100\nvar speed: float = 200.0\nvar player_name: String = \"Hero\"\nvar direction: Vector2 = Vector2.ZERO\n\n# Constants\nconst MAX_HEALTH: int = 100\nconst GRAVITY: float = 980.0\n\n# Functions — parameters and return type\nfunc take_damage(amount: int) -> void:\n    health -= amount\n\nfunc get_direction() -> Vector2:\n    return Input.get_vector(\"ui_left\", \"ui_right\", \"ui_up\", \"ui_down\")\n\n# Inferred typing with :=\nvar pos := Vector2(100, 200)     # inferred as Vector2\nvar items := []                  # inferred as Array (untyped)\nvar count := 0                   # inferred as int\n```\n\n### Typed Collections\n\n```gdscript\n# Typed arrays — only accepts the specified type\nvar enemies: Array[Enemy] = []\nvar scores: Array[int] = [10, 20, 30]\nvar names: Array[String] = [\"Alice\", \"Bob\"]\n\n# Typed dictionaries (Godot 4.4+)\nvar inventory: Dictionary[String, int] = {\"sword\": 1, \"potion\": 5}\n\n# Typed loop variable\nfor enemy: Enemy in enemies:\n    enemy.take_damage(10)\n\n# Typed array methods work with type safety\nvar filtered: Array[Enemy] = enemies.filter(func(e: Enemy) -> bool: return e.health > 0)\n```\n\n### Casting with `as` and `is`\n\n```gdscript\n# 'is' — type check (returns bool)\nfunc _on_body_entered(body: Node2D) -> void:\n    if body is Player:\n        var player: Player = body as Player\n        player.take_damage(10)\n\n# 'as' — cast (returns null on failure, no error)\nvar sprite := get_node(\"Sprite\") as Sprite2D\nif sprite:\n    sprite.modulate = Color.RED\n\n# Prefer 'is' check + cast over bare 'as' to avoid null surprises\n```\n\n### Enabling Strict Typing Warnings\n\nIn **Project > Project Settings > Debug > GDScript**:\n\n| Warning | Effect |\n|-------------------------|---------------------------------------------|\n| `UNTYPED_DECLARATION` | Warns on any untyped variable\u002Fparameter |\n| `INFERRED_DECLARATION` | Warns on `:=` (prefers explicit types) |\n| `UNSAFE_CAST` | Warns when an untyped (`Variant`) value is cast to a type |\n| `UNSAFE_CALL_ARGUMENT` | Warns when an argument's type is a supertype of the parameter's (`Node` into a `Node2D` parameter) |\n| `ONREADY_WITH_CAST` (Godot 4.8+) | Warns when an `@onready` initializer casts a `$Node` literal (`$Label as Label`), which may assign `null` |\n\n> Set warnings to **Error** for strict enforcement in team projects.\n\n### Typed Return Inheritance in Overrides\n\n> ⚠️ **Changed in Godot 4.7:** Methods that override a method with a typed return now inherit the return type, so an override without an explicit `return` statement becomes an error. Add `return null` (or a typed return value) at the end of the override. See the [4.7 migration guide](https:\u002F\u002Fdocs.godotengine.org\u002Fen\u002Flatest\u002Ftutorials\u002Fmigrating\u002Fupgrading_to_godot_4.7.html).\n\n```gdscript\nclass Enemy:\n    var weapon: Node\n    func get_weapon() -> Node:\n        return weapon\n\nclass UnarmedEnemy extends Enemy:\n    func get_weapon():  # 4.7+: inherits -> Node from Enemy\n        return null     # explicit return now required — omitting it is an error\n```\n\n---\n\n## 2. Await & Coroutines\n\n### Awaiting Signals\n\n`await` pauses the function until a signal fires, then resumes. The function becomes a coroutine.\n\n```gdscript\nfunc death_sequence() -> void:\n    $AnimationPlayer.play(\"death\")\n    await $AnimationPlayer.animation_finished  # pauses here\n\n    $Sprite2D.visible = false\n    await get_tree().create_timer(1.0).timeout  # wait 1 second\n\n    queue_free()\n```\n\n### Awaiting with Return Values\n\n```gdscript\n# Signal that passes data\nsignal dialogue_choice_made(choice: int)\n\nfunc show_dialogue(options: Array[String]) -> int:\n    # ... display UI ...\n    var choice: int = await dialogue_choice_made\n    return choice\n\n# Caller:\nfunc _on_npc_interact() -> void:\n    var result := await show_dialogue([\"Yes\", \"No\"])\n    if result == 0:\n        print(\"Player said yes\")\n```\n\n### Timer Patterns\n\n```gdscript\n# One-shot delay\nawait get_tree().create_timer(0.5).timeout\n\n# Repeating with await (simple but blocks the function)\nfor i in 5:\n    do_something()\n    await get_tree().create_timer(0.2).timeout\n\n# Non-blocking timer — use SceneTreeTimer or Tween instead\nget_tree().create_timer(2.0).timeout.connect(_on_delayed_action)\n```\n\n### Coroutine Safety\n\n```gdscript\n# DANGER: `target` may be freed while this coroutine waits\nfunc unsafe_coroutine(target: Node2D) -> void:\n    await get_tree().create_timer(5.0).timeout\n    target.position = Vector2.ZERO  # error: previously freed instance\n\n# SAFE: re-check other objects after every await\nfunc safe_coroutine(target: Node2D) -> void:\n    await get_tree().create_timer(5.0).timeout\n    if not is_instance_valid(target):\n        return\n    target.position = Vector2.ZERO\n```\n\nA freed node's own coroutine never resumes, so `is_instance_valid(self)` after `await` guards nothing.\n\n---\n\n## 3. Lambda Functions\n\nLambdas are inline anonymous functions for callbacks, sorting, and filtering, called with `.call()`. The reference covers single- and multi-line syntax, inline signal connections including `CONNECT_ONE_SHOT`, `Array` methods (`filter`, `map`, `reduce`, `any`, `all`, `sort_custom`), and closures, where locals are captured by value.\n\n> See [references\u002Flambda-functions.md](references\u002Flambda-functions.md) for the syntax, signal, `Array` method, and closure examples.\n\n---\n\n## 4. Match \u002F Pattern Matching\n\nGDScript's `match` is like `switch` but with pattern support.\n\n### Basic Match\n\n```gdscript\nmatch state:\n    State.IDLE:\n        play_idle()\n    State.RUNNING:\n        play_run()\n    State.JUMPING, State.FALLING:  # multiple patterns\n        play_air()\n    _:  # default (wildcard)\n        push_warning(\"Unknown state: %s\" % state)\n```\n\n### Pattern Types\n\n```gdscript\n# Literal patterns\nmatch value:\n    42:\n        print(\"The answer\")\n    \"hello\":\n        print(\"Greeting\")\n    true:\n        print(\"Boolean true\")\n\n# Binding pattern — captures value into a variable\nmatch command:\n    [\"move\", var direction]:\n        move(direction)\n    [\"attack\", var target, var damage]:\n        attack(target, damage)\n\n# Array pattern\nmatch input:\n    [1, 2, 3]:\n        print(\"Exact match\")\n    [1, ..]:\n        print(\"Starts with 1\")\n    [var first, _, var last]:\n        print(\"First: %s, Last: %s\" % [first, last])\n\n# Dictionary pattern\nmatch event:\n    {\"type\": \"damage\", \"amount\": var amt}:\n        take_damage(amt)\n    {\"type\": \"heal\", \"amount\": var amt}:\n        heal(amt)\n\n# Nested condition inside a branch\nmatch enemy_type:\n    \"boss\":\n        if health \u003C 50:\n            enter_rage_mode()\n        else:\n            normal_attack()\n```\n\n---\n\n## 5. Export Annotations\n\n`@export` exposes a variable to the Inspector. Hint variants (`@export_range`, `@export_enum`, `@export_file`) constrain editor input. Use `@export_group` and `@export_subgroup` to organize. Node and Resource exports use NodePath \u002F typed Resource references.\n\n> See [references\u002Fexport-annotations.md](references\u002Fexport-annotations.md) for the full export annotation catalog (basic exports, range\u002Fhint variants, groups, node and Resource exports).\n\n---\n\n## 6. Inner Classes & class_name\n\n### class_name\n\nRegister a script as a global class name — available everywhere without `preload`.\n\n```gdscript\n# item_data.gd\nclass_name ItemData\nextends Resource\n\n@export var name: String\n@export var icon: Texture2D\n@export var value: int\n\n# Now usable anywhere:\n# var item: ItemData = ItemData.new()\n# var items: Array[ItemData] = []\n```\n\n### Inner Classes\n\n```gdscript\n# Define a class inside another script\nclass HitResult:\n    var damage: int\n    var critical: bool\n    var knockback: Vector2\n\n    func _init(dmg: int, crit: bool, kb: Vector2 = Vector2.ZERO) -> void:\n        damage = dmg\n        critical = crit\n        knockback = kb\n\n# Usage\nfunc calculate_hit() -> HitResult:\n    var crit := randf() \u003C 0.2\n    var dmg := 10 * (2 if crit else 1)\n    return HitResult.new(dmg, crit, Vector2.RIGHT * 50)\n```\n\n---\n\n## 7. super() in Virtual Methods\n\nWhen you override a virtual method that the engine calls (`_ready`, `_process`, `_input`, etc.) and your parent class also implements it, call `super()` to chain the parent's behavior. Forgetting to call `super._ready()` is the most common cause of \"my base class init didn't run\" bugs.\n\n> See [references\u002Fsuper-in-virtual-methods.md](references\u002Fsuper-in-virtual-methods.md) for the full pattern (problem \u002F fix), the C# `base.X()` equivalent, and a catalog of bugs from missing super calls.\n\n---\n\n## 8. Common Idioms\n\nThe recurring small patterns: ternary expressions (`value if cond else other`), printf-style string formatting (`\"%s %d\" % [a, b]`), null\u002Fempty checks (`is_instance_valid` vs `!= null`, empty Array\u002FString checks), Dictionary access (`get(key, default)`), Array operations (`Array.has`, `Array.find`, `Array.has_all`), setget via `set` and `get` accessors.\n\n> See [references\u002Fcommon-idioms.md](references\u002Fcommon-idioms.md) for full code examples of each idiom.\n\n---\n\n## 9. Annotations Reference\n\n| Annotation | Purpose |\n|-----------------------|--------------------------------------------|\n| `@export` | Expose variable in Inspector |\n| `@export_range` | Numeric with slider |\n| `@export_enum` | Dropdown from string list |\n| `@export_file` | File path picker |\n| `@export_dir` | Directory picker |\n| `@export_multiline` | Multi-line text box |\n| `@export_group` | Group heading in Inspector |\n| `@export_subgroup` | Subgroup heading |\n| `@export_category` | Category divider |\n| `@onready` | Initialize when the node is ready, just before its `_ready()` body runs |\n| `@tool` | Run script in editor |\n| `@icon` | Custom icon for the script |\n| `@warning_ignore` | Suppress specific warning on next line |\n| `@static_unload` | Allow static variables to be freed |\n\n---\n\n## 10. Common Pitfalls\n\n| Symptom | Cause | Fix |\n|---------------------------------------|----------------------------------------------|------------------------------------------------------------------|\n| `as` cast silently returns `null` | Type mismatch — `as` doesn't error | Use `is` check first, then cast |\n| Await never resumes | Signal never emitted, or this node was freed (coroutine dropped) | Check the condition before awaiting; race slow signals against a timer |\n| Lambda's change to a variable is lost | Locals are captured by value | Keep shared state in a member, `Array` or `Dictionary` |\n| `UNTYPED_DECLARATION` warnings flood | Warning enabled but codebase isn't typed | Type incrementally; use `@warning_ignore` for legacy code |\n| Typed array assignment fails | A value that is a plain `Array` at runtime (a variable holding one, or the result of `map()` \u002F `filter()`) or an `Array[Subclass]` assigned to an `Array[Type]` variable (no covariance; subclass *elements* are accepted) | Declare it typed from the start, or `typed.assign(other)` |\n| `@onready` is `null` | Accessed before `_ready()` runs | Never access `@onready` vars in `_init()` or variable declarations |\n| Match doesn't enter any branch | No matching pattern and no `_:` wildcard | Always add `_:` default branch |\n| `class_name` conflict | Two scripts with same `class_name` | Use unique names; check for duplicates in Project |\n| Export group applies to wrong vars | Group scope continues until next group | Add a new `@export_group(\"\")` to end the group scope |\n| Parent `_ready()` logic doesn't run in child | Missing `super()` call in child's `_ready()` | Add `super()` as first line; see Section 7 |\n| `type_exists()` flagged as deprecated | Deprecated in Godot 4.7 | Use `ClassDB.class_exists()` instead |\n\n> ⚠️ **Changed in Godot 4.7:** The global `type_exists()` function is deprecated — replace `type_exists(\"Sprite2D\")` with `ClassDB.class_exists(\"Sprite2D\")`. See [GH-116899](https:\u002F\u002Fgithub.com\u002Fgodotengine\u002Fgodot\u002Fpull\u002F116899).\n\n---\n\n## 11. Variadic Functions (Godot 4.5+)\n\nGodot 4.5 added trailing-argument arrays via `...args`. The args are collected into an `Array`. Useful for printf-style helpers and flexible APIs without overloads.\n\n> See [references\u002Fvariadic-functions.md](references\u002Fvariadic-functions.md) for the full syntax, common patterns, and notes on when to prefer overloads.\n\n---\n\n## 12. Abstract Classes and Methods (Godot 4.5+)\n\nThe `@abstract` annotation prevents direct instantiation of a class and forces subclasses to implement any `@abstract`-annotated method (similar to C#'s `abstract` keyword).\n\n> See [references\u002Fabstract-classes.md](references\u002Fabstract-classes.md) for full base-class patterns and subclass implementation rules.\n\n---\n\n## 13. Implementation Checklist\n\n- [ ] All variables, parameters, and return types have explicit type hints\n- [ ] Typed arrays (`Array[Type]`) are used instead of untyped `Array` where possible\n- [ ] Other nodes used after an `await` are re-checked with `is_instance_valid()` (`self` needs no check)\n- [ ] Lambdas connected to signals are simple — complex logic goes in named methods\n- [ ] `match` statements include a `_:` default branch\n- [ ] `@export` variables use appropriate hints (`@export_range`, `@export_enum`, etc.)\n- [ ] `@export_group` organizes Inspector properties into logical sections\n- [ ] `class_name` is only used for scripts that need global visibility\n- [ ] `is` type check precedes `as` cast when the type isn't guaranteed\n- [ ] Properties with setters validate and clamp values\n- [ ] Overridden virtual methods call `super()` when extending non-built-in base classes\n- [ ] Variadic functions (`...args`) used when the number of trailing arguments is open-ended (Godot 4.5+)\n- [ ] Base classes that must not be instantiated use `@abstract`; required methods use `@abstract func` (Godot 4.5+)\n",{"name":5,"description":7},"master","60c28fdc40706a24576731e9fb3508b9c95258ad","skills\u002Fgdscript-patterns",63,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter","https:\u002F\u002Fgithub.com\u002Fjame581","https:\u002F\u002Fjanmesarc.online\u002F","Software engineer. My biggest passion is game development.","2026-11-14 20:45:49",{"source":8,"skillName":5,"commands":51,"prompt":61,"zipAvailable":62},[52,55,58],{"tool":53,"command":54},"npx","npx skills add jame581\u002FGodotPrompter --skill gdscript-patterns",{"tool":56,"command":57},"bunx","bunx skills add jame581\u002FGodotPrompter --skill gdscript-patterns",{"tool":59,"command":60},"pnpm","pnpm dlx skills add jame581\u002FGodotPrompter --skill gdscript-patterns","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fgdscript-patterns\u002FSKILL.md",true,[64,70,74,78,82,86],{"path":65,"resourceType":66,"resourceTypeDesc":67,"sizeBytes":68,"sourceHtmlUrl":69},"references\u002Fabstract-classes.md","REFERENCE","参考文档",2632,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fgdscript-patterns\u002Freferences\u002Fabstract-classes.md",{"path":71,"resourceType":66,"resourceTypeDesc":67,"sizeBytes":72,"sourceHtmlUrl":73},"references\u002Fcommon-idioms.md",2586,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fgdscript-patterns\u002Freferences\u002Fcommon-idioms.md",{"path":75,"resourceType":66,"resourceTypeDesc":67,"sizeBytes":76,"sourceHtmlUrl":77},"references\u002Fexport-annotations.md",1821,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fgdscript-patterns\u002Freferences\u002Fexport-annotations.md",{"path":79,"resourceType":66,"resourceTypeDesc":67,"sizeBytes":80,"sourceHtmlUrl":81},"references\u002Flambda-functions.md",2322,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fgdscript-patterns\u002Freferences\u002Flambda-functions.md",{"path":83,"resourceType":66,"resourceTypeDesc":67,"sizeBytes":84,"sourceHtmlUrl":85},"references\u002Fsuper-in-virtual-methods.md",2829,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fgdscript-patterns\u002Freferences\u002Fsuper-in-virtual-methods.md",{"path":87,"resourceType":66,"resourceTypeDesc":67,"sizeBytes":88,"sourceHtmlUrl":89},"references\u002Fvariadic-functions.md",1805,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fgdscript-patterns\u002Freferences\u002Fvariadic-functions.md",[91,111,132,156,172,189],{"skillNo":92,"name":93,"nameZh":6,"description":94,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":95,"categories":96,"keywords":97,"publishedAt":36},"01M6KRFE5BR2PSD08ZKDAS66R7","xr-development","Use when building VR\u002FAR\u002FXR applications — OpenXR setup, XROrigin3D, hand tracking, controllers, passthrough, and Meta Quest deployment in Godot 4.3+","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fxr-development\u002FSKILL.md",[],[98,99,22,100,101,102,103,104,105,106,107,25,108,109,110],"xr development","development","deployment","godot","vr","setup","tracking","godot 4","ar","hand","Meta","applications","quest",{"skillNo":112,"name":113,"nameZh":6,"description":114,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":115,"categories":116,"keywords":117,"publishedAt":36},"01M6KRF8GZTG1TAS506MFBSGFC","web-services","Use when a Godot game calls a web server — HTTPRequest, downloads, REST\u002FJSON APIs, auth headers, WebSocketPeer clients, TLS, retries, and keeping secrets out of the build. Not for game networking\u002FRPCs (multiplayer-basics) or browser export (web-export)","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fweb-services\u002FSKILL.md",[],[118,119,120,121,122,123,124,125,25,22,101,126,127,128,129,130,131],"web services","web","services","tls","retries","calling","auth","downloads","clients","headers","secrets","json","build","REST",{"skillNo":133,"name":134,"nameZh":6,"description":135,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":136,"categories":137,"keywords":138,"publishedAt":36},"01M6KRF38Q4WSKAYFS56PG87T0","web-export","Use when shipping a Godot game to the browser — Web export preset options, threads vs no-threads and COOP\u002FCOEP headers, hosting on itch.io or your own server, PWA, JavaScriptBridge, user:\u002F\u002F persistence, audio and input limits, and load size","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fweb-export\u002FSKILL.md",[],[119,31,139,140,141,142,143,144,127,145,146,22,147,148,149,150,151,152,25,153,154,155],"web export","threads","limits","shipping","size","options","hosting","input","Coop","preset","browser","game","io","load","pwa","Audio","server",{"skillNo":157,"name":158,"nameZh":6,"description":159,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":160,"categories":161,"keywords":162,"publishedAt":36},"01M6KREYFETEBH62ZTN6EZH2X3","using-godot-prompter","Bootstrap skill — establishes how to find and use GodotPrompter skills, with platform-specific tool mapping","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fusing-godot-prompter\u002FSKILL.md",[],[101,163,164,165,166,25,167,168,169,170,171],"using godot prompter","find","with","bootstrap","tool","platform","mapping","how","how to",{"skillNo":173,"name":174,"nameZh":6,"description":175,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":176,"categories":177,"keywords":178,"publishedAt":36},"01M6KRER5G7EQWKGAFN8QJKQ69","tween-animation","Use when implementing tweens — property animation, method tweening, chaining, parallel sequences, easing, and common UI\u002Fgameplay motion recipes","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Ftween-animation\u002FSKILL.md",[],[179,180,25,181,182,183,184,185,186,32,187,22,188],"tween animation","Animation","motion","parallel","gameplay","chaining","ui","recipes","implementing","sequences",{"skillNo":190,"name":191,"nameZh":6,"description":192,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":193,"categories":194,"keywords":195,"publishedAt":36},"01M6KREKGCQMVDV8WX7HWX8BZG","state-machine","Use when building a state machine or refactoring logic into one — enum, node, and resource-based FSM patterns with trade-offs. Not for adding states to an existing one","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fstate-machine\u002FSKILL.md",[],[196,197,198,101,22,20,199,200,201,202,165,25,187,203],"state","state machine","machine","node","fsm","state machines","trade","trade-offs"]