[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7FBMPYD0GE8MRF726F2RRKQ":3,"skill-same:01M7FBMPYD0GE8MRF726F2RRKQ":60},{"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":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":6,"ownerHtmlUrl":29,"ownerBlogUrl":6,"ownerDescription":30,"updatedAt":31,"install":32,"resources":45},"01M7FBMPYD0GE8MRF726F2RRKQ","godot-gdscript",null,"写或改 GDScript 时用。静态类型 := 与 Array[T] Dictionary[K, V]、class_name、@export @onready、信号 connect emit lambda、await 协程、match、setter getter、call_deferred、警告设置。GDScript typing, signals, coroutine, warnings.","MindsMaster\u002Fgodot-claude-code-skills","MindsMaster","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F167383411?v=4","01M7FBJFZBSAXET9TF9WDFRCJW","An5w1r","01M7FBJFZZRARX0F1VSWHTH9EM",3,"MIT","https:\u002F\u002Fgithub.com\u002FMindsMaster\u002Fgodot-claude-code-skills\u002Fblob\u002Fmaster\u002Fskills\u002Fgodot-gdscript\u002FSKILL.md",[],[],"2026-11-16 10:05:34",false,"---\nname: godot-gdscript\ndescription: 写或改 GDScript 时用。静态类型 := 与 Array[T] Dictionary[K, V]、class_name、@export @onready、信号 connect emit lambda、await 协程、match、setter getter、call_deferred、警告设置。GDScript typing, signals, coroutine, warnings.\n---\n\n# GDScript 写法\n\nGDScript 语言层的写法与陷阱：类型、注解、信号、协程、对象有效性、警告。断言与日志见 references\u002Fsyntax.md。目标 4.7，最低 4.4，更新的特性标版本号。\n\n## 范围\n\n| 不含 | 去哪 |\n|---|---|\n| 节点选型、场景组织、节点通信 | godot-scene-architecture |\n| 数据资源 | godot-resources-data |\n| C# 写法 | godot-csharp |\n| 卡顿与每帧分配 | godot-performance |\n| 无头加载脚本、抓警告 | godot-headless-testing |\n\n## 先查内置\n\n| 需求 | 用这个 | 别自己写 |\n|---|---|---|\n| 延时一次 | `await get_tree().create_timer(t).timeout` 或 Timer 节点 | `_process` 里累加 delta |\n| 周期执行 | Timer 节点的 `timeout` 信号 | `_process` 里 `if elapsed > 0.5` |\n| 输入轴 | `Input.get_vector()`、`Input.get_axis()` | 手写正负键相减 |\n| 数值靠近目标 | `move_toward()`、`lerp()`、`Tween` | 手写 SmoothDamp |\n| 取子节点 | `%Name`、`@export var x: Node`、`@onready` | 长硬路径 `get_node(\"..\u002F..\u002FA\u002FB\")` |\n| 枚举名字互转 | `State.keys()`、`State.find_key(v)`、`State[\"RUN\"]` | match 字符串表 |\n| 数组变换 | `filter` `map` `reduce` `any` `all` `pick_random` `sort_custom` | for 加临时数组 |\n| 随机 | `randi_range()`、`randf_range()`、`RandomNumberGenerator` | 自写 LCG |\n| 浮点比较 | `is_equal_approx()`、`is_zero_approx()` | `==` 比较浮点 |\n| 帧末调用 | `callable.call_deferred()`、`set_deferred()` | 用 Timer 凑一帧 |\n| 数据放 Inspector 里改 | `Resource` 子类加 `@export` | JSON 手写解析 |\n\n## 做法\n\n### 静态类型\n\n\u003C!-- check: gdonly -->\n```gdscript\nextends Node\n\nvar speed: float = 200.0\nvar hp := 10\nvar names: Array[String] = []\nvar scores: Dictionary[StringName, int] = {}\nvar target: Node2D\n\nfunc take_damage(amount: int) -> bool:\n\thp -= amount\n\treturn hp \u003C= 0\n\nfunc _ready() -> void:\n\tvar raw: Dictionary = {\"k\": 1}\n\tvar value: int = raw[\"k\"]\n\tvar sprite := get_node_or_null(\"Sprite\") as Sprite2D\n\tprint(value, sprite)\n```\n\n| 写法 | 结果 | 改法 |\n|---|---|---|\n| `:=` 右值是 Variant，如无类型 Dictionary 取值、`call()` | 错误 `inference_on_variant` | `var v: int = raw[\"k\"]` |\n| `var x := max(a, b)` | 同上，`clamp` `min` `max` `lerp` `abs` `sign` `floor` `ceil` `round` `snapped` 都返回 Variant | 用 `maxf` `clampi` 这类带类型版本 |\n| `load(path)` | 返回 `Resource` | `var tex: Texture2D = load(path)`，常量路径用 `preload()` |\n| `$Node`、`get_node()` | 返回 `Node` | `@onready var sprite: Sprite2D = $Sprite` |\n| `x as Sprite2D` 类型不符 | 静默得 `null` | 只在就要这个结果时用 |\n| `map()` 结果赋给 `Array[T]` | 报错，`map()` 返回无类型 Array | `typed.assign(untyped)` |\n| 整数传给枚举参数 | `int_as_enum_without_cast` | 写成员名或显式转换 |\n\n- `Array[T]` 运行时强制元素类型，`filter()` 保留元素类型\n- `Dictionary[K, V]` 4.4+，不支持再嵌套类型\n- 循环变量写类型：`for n: Node in nodes:`\n- 大量数值用 `PackedFloat32Array`，`Array[float]` 仍是 Variant 数组\n- 对象类型可为 `null`，数值与字符串类型不可\n\n### class_name 与 preload\n\n- `class_name Foo` 注册全局类，任何脚本可直接当类型和构造\n- 类名不能与 autoload 同名，报 `Class \"Foo\" hides an autoload singleton`\n- 类名不能与引擎类同名\n- 无 `class_name` 的脚本用常量引用，`preload` 参数须是常量字符串\n- 路径运行时才定用 `load()`\n\n\u003C!-- check: skip; gdonly -->\n```gdscript\nconst Rifle := preload(\"res:\u002F\u002Fweapons\u002Frifle.gd\")\n\nvar main_weapon: Rifle = Rifle.new()\n```\n\n- 两个脚本互相 `preload` 在 4.7 可加载，仍建议用 `class_name` 打断环\n- `@export` 类型只能是内置类型、`Resource`、`Node`、枚举\n- 3.x 的 `export var` `onready var` `yield` `connect(\"sig\", obj, \"method\")` 在 4.x 都没了\n\n### 注解\n\n\u003C!-- check: gdonly -->\n```gdscript\nextends Node2D\n\n@export var speed: float = 200.0\n@export_range(0.0, 1.0, 0.01) var ratio := 0.5\n@export_enum(\"Idle\", \"Run\") var mode: int = 0\n@export_file(\"*.tscn\") var next_scene: String\n@export var bullet_scene: PackedScene\n@export var spawn_point: Marker2D\n@export_flags_2d_physics var hit_mask: int\n\n@export_group(\"Loot\")\n@export var drops: Array[Resource] = []\n\n@onready var label: Label = %Label\n@onready var timer: Timer = $Timer\n\nfunc _ready() -> void:\n\ttimer.start()\n\tlabel.text = str(speed)\n```\n\n全表见 [references\u002Fannotations.md](references\u002Fannotations.md)。\n\n| 时刻 | 发生 |\n|---|---|\n| 声明初值 | 脚本默认值 |\n| `_init()` | 读到的是默认值 |\n| 场景保存的值赋入 | 导出变量的 setter 此时调用，`@onready` 变量仍是 `null` |\n| `@onready` 赋值 | 紧接着 `_ready()` |\n\n- `@export` 的类型来自标注或默认值，都没有是解析错误，要 Variant 写 `: Variant`\n- `@export var n: Node` 只在 Node 派生脚本里可用\n- setter 里用节点前判断 `is_node_ready()`\n- `@onready` 与 `@export` 同用是错误 `onready_with_export`\n- 成员默认值里用 `$` 不带 `@onready` 是错误 `get_node_default_without_onready`\n- 代码 `add_child()` 的节点直接赋成员，不需要 `@onready`\n- 场景里已存的属性值覆盖脚本的新默认值\n- 导出 `Resource` 随场景一起加载，大资源用 `@export_file` 存路径，用时 `load()`\n- 4.5+ `@export_file` 存 UID，要原始路径用 `@export_file_path`\n- `@export_tool_button(\"名字\")` 4.4+，须配 `@tool`\n\n### 信号\n\n\u003C!-- check: gdonly -->\n```gdscript\nextends Node\n\nsignal died\nsignal damaged(amount: int, source: Node)\n\n@export var button: Button\n\nfunc _ready() -> void:\n\tbutton.pressed.connect(_on_pressed)\n\tdamaged.connect(_log_damage.bind(\"player\"))\n\tdied.connect(queue_free, CONNECT_ONE_SHOT)\n\nfunc _on_pressed() -> void:\n\tdamaged.emit(3, self)\n\nfunc _log_damage(amount: int, _source: Node, tag: String) -> void:\n\tprint(tag, amount)\n```\n\n- `bind()` 的参数追加在发射参数之后，`unbind(n)` 丢掉末尾 n 个发射参数\n- 同一 Callable 连两次返回 `ERR_INVALID_PARAMETER` 并打印错误，先 `is_connected()`\n- `CONNECT_ONE_SHOT` 触发一次后断开，`CONNECT_DEFERRED` 推迟到帧末\n- 接收者释放时连接自动断开，lambda 捕获 `self` 成员时也一样\n- 只由外部发射的信号加 `@warning_ignore(\"unused_signal\")`\n- `emit()` 不检查参数类型，接收方法参数类型不符时调用报错\n\n\u003C!-- check: gdonly -->\n```gdscript\nextends Node\n\nfunc _ready() -> void:\n\tvar stats: Dictionary = {\"count\": 0}\n\tvar bump := func() -> void:\n\t\tstats[\"count\"] += 1\n\tbump.call()\n\tbump.call()\n\tprint(stats[\"count\"])\n```\n\n- lambda 创建时按值捕获局部变量一次\n- lambda 里 `count += 1` 只改副本，触发 `confusable_capture_reassignment`\n- 要回写就捕获 Array、Dictionary 或对象，改其内容\n\n### await 与协程\n\n\u003C!-- check: gdonly -->\n```gdscript\nextends Node\n\nsignal answered(choice: int)\n\nfunc open_door(door: Node3D) -> void:\n\tawait get_tree().create_timer(1.0).timeout\n\tif not is_inside_tree() or not is_instance_valid(door):\n\t\treturn\n\tdoor.hide()\n\nfunc ask() -> int:\n\tvar choice: int = await answered\n\treturn choice\n```\n\n| 情况 | 结果 |\n|---|---|\n| 调用协程不写 `await` | 跑到第一个 `await` 就返回，`missing_await` 默认关 |\n| 信号带 1 个参数 | `await` 得到该值 |\n| 信号带多个参数 | 得到 Array |\n| 信号无参数 | 得到 `null` |\n| `await` 期间自己离开场景树 | `get_tree()` 打印错误并返回 `null` |\n| `await` 期间自己被 `free()` | 协程不再恢复，后面的清理不执行 |\n\n- `await` 之后先检查 `is_inside_tree()` 和目标 `is_instance_valid()`\n- 要清理的状态放 `_exit_tree()` 或 `tree_exiting` 里复位\n- `create_timer` 默认暂停时也走，要受暂停影响第二参数传 `false`\n- 等一帧 `await get_tree().process_frame`，等物理帧 `physics_frame`\n- 没有内置超时，用 Timer 的 `timeout` 和业务信号谁先到谁处理\n\n### 对象有效性\n\n| 对象 | 规则 |\n|---|---|\n| 已 `free()` 的对象变量 | 不自动变 `null`，访问报 `previously freed`，用 `is_instance_valid()` 判断 |\n| `queue_free()` 后帧末前 | `is_instance_valid()` 仍为真，用 `is_queued_for_deletion()` |\n| `RefCounted`、`Resource` | 引用计数，不悬空，不用 `free()` |\n| 长期持有可能被释放的节点 | 存 `weakref(node)`，用时 `get_ref()` |\n\n- 物理回调、信号回调、遍历子节点时释放用 `queue_free()`\n- `_init()` 里节点不在树内，`get_node()` 失败\n\n### Callable 与延迟调用\n\n\u003C!-- check: gdonly -->\n```gdscript\nextends Node\n\nfunc _ready() -> void:\n\tvar child := Node.new()\n\tadd_child.call_deferred(child)\n\tset_deferred(&\"process_mode\", Node.PROCESS_MODE_DISABLED)\n\tvar sorted: Array[int] = [3, 1, 2]\n\tsorted.sort_custom(func(a: int, b: int) -> bool: return a > b)\n```\n\n- `call_deferred` 在当前帧空闲阶段末尾执行，返回值永远是 `null`\n- 物理回调里改碰撞形状、`Area2D.monitoring`、`CollisionShape2D.disabled` 用 `set_deferred`\n- 线程里碰场景树只能 `call_deferred`\n- 方法引用写 `_on_pressed`，不写 `Callable(self, \"_on_pressed\")`\n- `callable.is_valid()` 判断绑定对象是否还在\n\n### 警告设置\n\n项目设置 `debug\u002Fgdscript\u002Fwarnings\u002F*`，0 忽略、1 警告、2 错误，高级设置里可见。全表见 [references\u002Fwarnings.md](references\u002Fwarnings.md)。全类型化项目建议：\n\n```ini\n[debug]\n\ngdscript\u002Fwarnings\u002Funtyped_declaration=2\ngdscript\u002Fwarnings\u002Fmissing_await=2\ngdscript\u002Fwarnings\u002Fnarrowing_conversion=2\ngdscript\u002Fwarnings\u002Fint_as_enum_without_cast=2\ngdscript\u002Fwarnings\u002Funassigned_variable=2\n```\n\n- 单句忽略 `@warning_ignore(\"unused_signal\")`\n- 区域忽略 `@warning_ignore_start` 与 `@warning_ignore_restore`\n- `directory_rules` 默认忽略 `res:\u002F\u002Faddons`\n\n## 陷阱\n\nmatch、静态成员、setter、super 的完整写法见 [references\u002Fsyntax.md](references\u002Fsyntax.md)。\n\n| 现象 | 做法 |\n|---|---|\n| `5 \u002F 2` 得 `2`，触发 `integer_division` | `5 \u002F 2.0` 或 `float(a) \u002F b` |\n| `var b = a` 后改 `b`，`a` 也变 | Array Dictionary 按引用传递，`duplicate()`，嵌套 `duplicate(true)` |\n| `const` 数组 `append` 报 `Array is in read-only state` | `const` 集合只读，改用 `var` |\n| 父类 `_init()` `_ready()` 没执行 | 子类覆盖后要显式 `super()` |\n| 声明初值没触发 setter | 初值不调 setter，类内其他赋值才调 |\n| `unused_parameter` | 参数名加下划线前缀 `_delta` |\n| `narrowing_conversion` | 浮点传整数参数时 `int()` `roundi()` `floori()` |\n| 固定种子不生效 | 运行时已自动 `randomize()`，用 `seed()`，之后别再 `randomize()` |\n| 遍历数组时增删元素跳项 | 遍历 `arr.duplicate()` 或倒序下标 |\n| `call(\"do_it\")` 拼写错到运行时才暴露 | 用 Callable 引用与信号对象 |\n| `native_method_override` 报错 | 方法与引擎原生方法同名，改名 |\n| `shadowed_variable` | 局部变量与成员同名，改名 |\n| 带 `static var` 的脚本持有大资源不释放 | 脚本不会卸载，手动清空 |\n\n## 参考\n\n- [references\u002Fannotations.md](references\u002Fannotations.md)：导出与其他注解全表\n- [references\u002Fsyntax.md](references\u002Fsyntax.md)：match、静态成员、StringName、setter、super、可变参数与抽象类、断言与日志\n- [references\u002Fwarnings.md](references\u002Fwarnings.md)：全部警告与默认值\n- https:\u002F\u002Fdocs.godotengine.org\u002Fen\u002Fstable\u002Ftutorials\u002Fscripting\u002Fgdscript\u002Fgdscript_basics.html\n- https:\u002F\u002Fdocs.godotengine.org\u002Fen\u002Fstable\u002Ftutorials\u002Fscripting\u002Fgdscript\u002Fstatic_typing.html\n- https:\u002F\u002Fdocs.godotengine.org\u002Fen\u002Fstable\u002Ftutorials\u002Fscripting\u002Fgdscript\u002Fgdscript_exports.html\n- https:\u002F\u002Fdocs.godotengine.org\u002Fen\u002Fstable\u002Ftutorials\u002Fscripting\u002Fgdscript\u002Fwarning_system.html\n","# GDScript 写法\n\nGDScript 语言层的写法与陷阱：类型、注解、信号、协程、对象有效性、警告。断言与日志见 references\u002Fsyntax.md。目标 4.7，最低 4.4，更新的特性标版本号。\n\n## 范围\n\n| 不含 | 去哪 |\n|---|---|\n| 节点选型、场景组织、节点通信 | godot-scene-architecture |\n| 数据资源 | godot-resources-data |\n| C# 写法 | godot-csharp |\n| 卡顿与每帧分配 | godot-performance |\n| 无头加载脚本、抓警告 | godot-headless-testing |\n\n## 先查内置\n\n| 需求 | 用这个 | 别自己写 |\n|---|---|---|\n| 延时一次 | `await get_tree().create_timer(t).timeout` 或 Timer 节点 | `_process` 里累加 delta |\n| 周期执行 | Timer 节点的 `timeout` 信号 | `_process` 里 `if elapsed > 0.5` |\n| 输入轴 | `Input.get_vector()`、`Input.get_axis()` | 手写正负键相减 |\n| 数值靠近目标 | `move_toward()`、`lerp()`、`Tween` | 手写 SmoothDamp |\n| 取子节点 | `%Name`、`@export var x: Node`、`@onready` | 长硬路径 `get_node(\"..\u002F..\u002FA\u002FB\")` |\n| 枚举名字互转 | `State.keys()`、`State.find_key(v)`、`State[\"RUN\"]` | match 字符串表 |\n| 数组变换 | `filter` `map` `reduce` `any` `all` `pick_random` `sort_custom` | for 加临时数组 |\n| 随机 | `randi_range()`、`randf_range()`、`RandomNumberGenerator` | 自写 LCG |\n| 浮点比较 | `is_equal_approx()`、`is_zero_approx()` | `==` 比较浮点 |\n| 帧末调用 | `callable.call_deferred()`、`set_deferred()` | 用 Timer 凑一帧 |\n| 数据放 Inspector 里改 | `Resource` 子类加 `@export` | JSON 手写解析 |\n\n## 做法\n\n### 静态类型\n\n\u003C!-- check: gdonly -->\n```gdscript\nextends Node\n\nvar speed: float = 200.0\nvar hp := 10\nvar names: Array[String] = []\nvar scores: Dictionary[StringName, int] = {}\nvar target: Node2D\n\nfunc take_damage(amount: int) -> bool:\n\thp -= amount\n\treturn hp \u003C= 0\n\nfunc _ready() -> void:\n\tvar raw: Dictionary = {\"k\": 1}\n\tvar value: int = raw[\"k\"]\n\tvar sprite := get_node_or_null(\"Sprite\") as Sprite2D\n\tprint(value, sprite)\n```\n\n| 写法 | 结果 | 改法 |\n|---|---|---|\n| `:=` 右值是 Variant，如无类型 Dictionary 取值、`call()` | 错误 `inference_on_variant` | `var v: int = raw[\"k\"]` |\n| `var x := max(a, b)` | 同上，`clamp` `min` `max` `lerp` `abs` `sign` `floor` `ceil` `round` `snapped` 都返回 Variant | 用 `maxf` `clampi` 这类带类型版本 |\n| `load(path)` | 返回 `Resource` | `var tex: Texture2D = load(path)`，常量路径用 `preload()` |\n| `$Node`、`get_node()` | 返回 `Node` | `@onready var sprite: Sprite2D = $Sprite` |\n| `x as Sprite2D` 类型不符 | 静默得 `null` | 只在就要这个结果时用 |\n| `map()` 结果赋给 `Array[T]` | 报错，`map()` 返回无类型 Array | `typed.assign(untyped)` |\n| 整数传给枚举参数 | `int_as_enum_without_cast` | 写成员名或显式转换 |\n\n- `Array[T]` 运行时强制元素类型，`filter()` 保留元素类型\n- `Dictionary[K, V]` 4.4+，不支持再嵌套类型\n- 循环变量写类型：`for n: Node in nodes:`\n- 大量数值用 `PackedFloat32Array`，`Array[float]` 仍是 Variant 数组\n- 对象类型可为 `null`，数值与字符串类型不可\n\n### class_name 与 preload\n\n- `class_name Foo` 注册全局类，任何脚本可直接当类型和构造\n- 类名不能与 autoload 同名，报 `Class \"Foo\" hides an autoload singleton`\n- 类名不能与引擎类同名\n- 无 `class_name` 的脚本用常量引用，`preload` 参数须是常量字符串\n- 路径运行时才定用 `load()`\n\n\u003C!-- check: skip; gdonly -->\n```gdscript\nconst Rifle := preload(\"res:\u002F\u002Fweapons\u002Frifle.gd\")\n\nvar main_weapon: Rifle = Rifle.new()\n```\n\n- 两个脚本互相 `preload` 在 4.7 可加载，仍建议用 `class_name` 打断环\n- `@export` 类型只能是内置类型、`Resource`、`Node`、枚举\n- 3.x 的 `export var` `onready var` `yield` `connect(\"sig\", obj, \"method\")` 在 4.x 都没了\n\n### 注解\n\n\u003C!-- check: gdonly -->\n```gdscript\nextends Node2D\n\n@export var speed: float = 200.0\n@export_range(0.0, 1.0, 0.01) var ratio := 0.5\n@export_enum(\"Idle\", \"Run\") var mode: int = 0\n@export_file(\"*.tscn\") var next_scene: String\n@export var bullet_scene: PackedScene\n@export var spawn_point: Marker2D\n@export_flags_2d_physics var hit_mask: int\n\n@export_group(\"Loot\")\n@export var drops: Array[Resource] = []\n\n@onready var label: Label = %Label\n@onready var timer: Timer = $Timer\n\nfunc _ready() -> void:\n\ttimer.start()\n\tlabel.text = str(speed)\n```\n\n全表见 [references\u002Fannotations.md](references\u002Fannotations.md)。\n\n| 时刻 | 发生 |\n|---|---|\n| 声明初值 | 脚本默认值 |\n| `_init()` | 读到的是默认值 |\n| 场景保存的值赋入 | 导出变量的 setter 此时调用，`@onready` 变量仍是 `null` |\n| `@onready` 赋值 | 紧接着 `_ready()` |\n\n- `@export` 的类型来自标注或默认值，都没有是解析错误，要 Variant 写 `: Variant`\n- `@export var n: Node` 只在 Node 派生脚本里可用\n- setter 里用节点前判断 `is_node_ready()`\n- `@onready` 与 `@export` 同用是错误 `onready_with_export`\n- 成员默认值里用 `$` 不带 `@onready` 是错误 `get_node_default_without_onready`\n- 代码 `add_child()` 的节点直接赋成员，不需要 `@onready`\n- 场景里已存的属性值覆盖脚本的新默认值\n- 导出 `Resource` 随场景一起加载，大资源用 `@export_file` 存路径，用时 `load()`\n- 4.5+ `@export_file` 存 UID，要原始路径用 `@export_file_path`\n- `@export_tool_button(\"名字\")` 4.4+，须配 `@tool`\n\n### 信号\n\n\u003C!-- check: gdonly -->\n```gdscript\nextends Node\n\nsignal died\nsignal damaged(amount: int, source: Node)\n\n@export var button: Button\n\nfunc _ready() -> void:\n\tbutton.pressed.connect(_on_pressed)\n\tdamaged.connect(_log_damage.bind(\"player\"))\n\tdied.connect(queue_free, CONNECT_ONE_SHOT)\n\nfunc _on_pressed() -> void:\n\tdamaged.emit(3, self)\n\nfunc _log_damage(amount: int, _source: Node, tag: String) -> void:\n\tprint(tag, amount)\n```\n\n- `bind()` 的参数追加在发射参数之后，`unbind(n)` 丢掉末尾 n 个发射参数\n- 同一 Callable 连两次返回 `ERR_INVALID_PARAMETER` 并打印错误，先 `is_connected()`\n- `CONNECT_ONE_SHOT` 触发一次后断开，`CONNECT_DEFERRED` 推迟到帧末\n- 接收者释放时连接自动断开，lambda 捕获 `self` 成员时也一样\n- 只由外部发射的信号加 `@warning_ignore(\"unused_signal\")`\n- `emit()` 不检查参数类型，接收方法参数类型不符时调用报错\n\n\u003C!-- check: gdonly -->\n```gdscript\nextends Node\n\nfunc _ready() -> void:\n\tvar stats: Dictionary = {\"count\": 0}\n\tvar bump := func() -> void:\n\t\tstats[\"count\"] += 1\n\tbump.call()\n\tbump.call()\n\tprint(stats[\"count\"])\n```\n\n- lambda 创建时按值捕获局部变量一次\n- lambda 里 `count += 1` 只改副本，触发 `confusable_capture_reassignment`\n- 要回写就捕获 Array、Dictionary 或对象，改其内容\n\n### await 与协程\n\n\u003C!-- check: gdonly -->\n```gdscript\nextends Node\n\nsignal answered(choice: int)\n\nfunc open_door(door: Node3D) -> void:\n\tawait get_tree().create_timer(1.0).timeout\n\tif not is_inside_tree() or not is_instance_valid(door):\n\t\treturn\n\tdoor.hide()\n\nfunc ask() -> int:\n\tvar choice: int = await answered\n\treturn choice\n```\n\n| 情况 | 结果 |\n|---|---|\n| 调用协程不写 `await` | 跑到第一个 `await` 就返回，`missing_await` 默认关 |\n| 信号带 1 个参数 | `await` 得到该值 |\n| 信号带多个参数 | 得到 Array |\n| 信号无参数 | 得到 `null` |\n| `await` 期间自己离开场景树 | `get_tree()` 打印错误并返回 `null` |\n| `await` 期间自己被 `free()` | 协程不再恢复，后面的清理不执行 |\n\n- `await` 之后先检查 `is_inside_tree()` 和目标 `is_instance_valid()`\n- 要清理的状态放 `_exit_tree()` 或 `tree_exiting` 里复位\n- `create_timer` 默认暂停时也走，要受暂停影响第二参数传 `false`\n- 等一帧 `await get_tree().process_frame`，等物理帧 `physics_frame`\n- 没有内置超时，用 Timer 的 `timeout` 和业务信号谁先到谁处理\n\n### 对象有效性\n\n| 对象 | 规则 |\n|---|---|\n| 已 `free()` 的对象变量 | 不自动变 `null`，访问报 `previously freed`，用 `is_instance_valid()` 判断 |\n| `queue_free()` 后帧末前 | `is_instance_valid()` 仍为真，用 `is_queued_for_deletion()` |\n| `RefCounted`、`Resource` | 引用计数，不悬空，不用 `free()` |\n| 长期持有可能被释放的节点 | 存 `weakref(node)`，用时 `get_ref()` |\n\n- 物理回调、信号回调、遍历子节点时释放用 `queue_free()`\n- `_init()` 里节点不在树内，`get_node()` 失败\n\n### Callable 与延迟调用\n\n\u003C!-- check: gdonly -->\n```gdscript\nextends Node\n\nfunc _ready() -> void:\n\tvar child := Node.new()\n\tadd_child.call_deferred(child)\n\tset_deferred(&\"process_mode\", Node.PROCESS_MODE_DISABLED)\n\tvar sorted: Array[int] = [3, 1, 2]\n\tsorted.sort_custom(func(a: int, b: int) -> bool: return a > b)\n```\n\n- `call_deferred` 在当前帧空闲阶段末尾执行，返回值永远是 `null`\n- 物理回调里改碰撞形状、`Area2D.monitoring`、`CollisionShape2D.disabled` 用 `set_deferred`\n- 线程里碰场景树只能 `call_deferred`\n- 方法引用写 `_on_pressed`，不写 `Callable(self, \"_on_pressed\")`\n- `callable.is_valid()` 判断绑定对象是否还在\n\n### 警告设置\n\n项目设置 `debug\u002Fgdscript\u002Fwarnings\u002F*`，0 忽略、1 警告、2 错误，高级设置里可见。全表见 [references\u002Fwarnings.md](references\u002Fwarnings.md)。全类型化项目建议：\n\n```ini\n[debug]\n\ngdscript\u002Fwarnings\u002Funtyped_declaration=2\ngdscript\u002Fwarnings\u002Fmissing_await=2\ngdscript\u002Fwarnings\u002Fnarrowing_conversion=2\ngdscript\u002Fwarnings\u002Fint_as_enum_without_cast=2\ngdscript\u002Fwarnings\u002Funassigned_variable=2\n```\n\n- 单句忽略 `@warning_ignore(\"unused_signal\")`\n- 区域忽略 `@warning_ignore_start` 与 `@warning_ignore_restore`\n- `directory_rules` 默认忽略 `res:\u002F\u002Faddons`\n\n## 陷阱\n\nmatch、静态成员、setter、super 的完整写法见 [references\u002Fsyntax.md](references\u002Fsyntax.md)。\n\n| 现象 | 做法 |\n|---|---|\n| `5 \u002F 2` 得 `2`，触发 `integer_division` | `5 \u002F 2.0` 或 `float(a) \u002F b` |\n| `var b = a` 后改 `b`，`a` 也变 | Array Dictionary 按引用传递，`duplicate()`，嵌套 `duplicate(true)` |\n| `const` 数组 `append` 报 `Array is in read-only state` | `const` 集合只读，改用 `var` |\n| 父类 `_init()` `_ready()` 没执行 | 子类覆盖后要显式 `super()` |\n| 声明初值没触发 setter | 初值不调 setter，类内其他赋值才调 |\n| `unused_parameter` | 参数名加下划线前缀 `_delta` |\n| `narrowing_conversion` | 浮点传整数参数时 `int()` `roundi()` `floori()` |\n| 固定种子不生效 | 运行时已自动 `randomize()`，用 `seed()`，之后别再 `randomize()` |\n| 遍历数组时增删元素跳项 | 遍历 `arr.duplicate()` 或倒序下标 |\n| `call(\"do_it\")` 拼写错到运行时才暴露 | 用 Callable 引用与信号对象 |\n| `native_method_override` 报错 | 方法与引擎原生方法同名，改名 |\n| `shadowed_variable` | 局部变量与成员同名，改名 |\n| 带 `static var` 的脚本持有大资源不释放 | 脚本不会卸载，手动清空 |\n\n## 参考\n\n- [references\u002Fannotations.md](references\u002Fannotations.md)：导出与其他注解全表\n- [references\u002Fsyntax.md](references\u002Fsyntax.md)：match、静态成员、StringName、setter、super、可变参数与抽象类、断言与日志\n- [references\u002Fwarnings.md](references\u002Fwarnings.md)：全部警告与默认值\n- https:\u002F\u002Fdocs.godotengine.org\u002Fen\u002Fstable\u002Ftutorials\u002Fscripting\u002Fgdscript\u002Fgdscript_basics.html\n- https:\u002F\u002Fdocs.godotengine.org\u002Fen\u002Fstable\u002Ftutorials\u002Fscripting\u002Fgdscript\u002Fstatic_typing.html\n- https:\u002F\u002Fdocs.godotengine.org\u002Fen\u002Fstable\u002Ftutorials\u002Fscripting\u002Fgdscript\u002Fgdscript_exports.html\n- https:\u002F\u002Fdocs.godotengine.org\u002Fen\u002Fstable\u002Ftutorials\u002Fscripting\u002Fgdscript\u002Fwarning_system.html\n",{"name":5,"description":7},"master","d9cc24874d2a7b2d0f9fa2382a02c42969a1e092","skills\u002Fgodot-gdscript",0,"https:\u002F\u002Fgithub.com\u002FMindsMaster\u002Fgodot-claude-code-skills","https:\u002F\u002Fgithub.com\u002FMindsMaster","Full-stack developer","2026-11-10 12:36:07",{"source":8,"skillName":5,"commands":33,"prompt":43,"zipAvailable":44},[34,37,40],{"tool":35,"command":36},"npx","npx skills add MindsMaster\u002Fgodot-claude-code-skills --skill godot-gdscript",{"tool":38,"command":39},"bunx","bunx skills add MindsMaster\u002Fgodot-claude-code-skills --skill godot-gdscript",{"tool":41,"command":42},"pnpm","pnpm dlx skills add MindsMaster\u002Fgodot-claude-code-skills --skill godot-gdscript","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FMindsMaster\u002Fgodot-claude-code-skills\u002Fblob\u002Fmaster\u002Fskills\u002Fgodot-gdscript\u002FSKILL.md",true,[46,52,56],{"path":47,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":50,"sourceHtmlUrl":51},"references\u002Fannotations.md","REFERENCE","参考文档",4586,"https:\u002F\u002Fgithub.com\u002FMindsMaster\u002Fgodot-claude-code-skills\u002Fblob\u002Fmaster\u002Fskills\u002Fgodot-gdscript\u002Freferences\u002Fannotations.md",{"path":53,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":54,"sourceHtmlUrl":55},"references\u002Fsyntax.md",4931,"https:\u002F\u002Fgithub.com\u002FMindsMaster\u002Fgodot-claude-code-skills\u002Fblob\u002Fmaster\u002Fskills\u002Fgodot-gdscript\u002Freferences\u002Fsyntax.md",{"path":57,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":58,"sourceHtmlUrl":59},"references\u002Fwarnings.md",4928,"https:\u002F\u002Fgithub.com\u002FMindsMaster\u002Fgodot-claude-code-skills\u002Fblob\u002Fmaster\u002Fskills\u002Fgodot-gdscript\u002Freferences\u002Fwarnings.md",[61,68,75,82,89,96],{"skillNo":62,"name":63,"nameZh":6,"description":64,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":65,"categories":66,"keywords":67,"publishedAt":19},"01M7FBP7NJ4NTGA239X15MXQPK","godot-ui","写菜单 HUD 对话框 血条 设置界面 本地化 分辨率适配 UI 导航时用，做设置即时生效 窗口模式 全屏 窗口尺寸确认还原 失焦暂停时也用。Control 布局 Container anchors、项目级 Theme 统一字体、StyleBox、ProgressBar 血条、RichTextLabel、多分辨率 stretch aspect、tr() 本地化、手柄焦点导航、mouse_filter 吃点击、CanvasLayer HUD、弹窗 拖放。UI layout, theme, localization, settings menu, fullscreen, pause on focus loss.","https:\u002F\u002Fgithub.com\u002FMindsMaster\u002Fgodot-claude-code-skills\u002Fblob\u002Fmaster\u002Fskills\u002Fgodot-ui\u002FSKILL.md",[],[],{"skillNo":69,"name":70,"nameZh":6,"description":71,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":72,"categories":73,"keywords":74,"publishedAt":19},"01M7FBP23RTBQ2ZW9SKXE37SFS","godot-shaders-vfx","做受击闪白 受伤变白 命中闪烁 溶解 描边，或从 GDScript 与 C# 改 .gdshader 的 shader 参数 SetInstanceShaderParameter set_shader_parameter 时先用，多个敌人共用一份材质各自闪白也归这里。也管内置材质与 shader 的取舍、instance uniform、屏幕与深度纹理、GPUParticles 粒子、后处理顺序。shaders, hit flash, particles, post-processing.","https:\u002F\u002Fgithub.com\u002FMindsMaster\u002Fgodot-claude-code-skills\u002Fblob\u002Fmaster\u002Fskills\u002Fgodot-shaders-vfx\u002FSKILL.md",[],[],{"skillNo":76,"name":77,"nameZh":6,"description":78,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":79,"categories":80,"keywords":81,"publishedAt":19},"01M7FBNVCNBKPFGQF5P5QJZMXK","godot-scene-authoring","在 Godot 4 里新做关卡、房间、HUD、菜单、NPC、道具、背景时用，决定内容摆进 .tscn 还是代码运行时搭。新建项目第一个场景，往已有项目加场景，打开场景一片空看不到东西，美术策划要在编辑器里直接看和调，自定义显示节点在编辑器里不显示，@tool 节点把材质 z_index 写进 tscn，确定性模拟 联机 服务器要读场景里摆的位置。先自查项目是摆在场景里还是运行时生成，再按结果新做或迁移。脚本生成 tscn、@tool 自绘节点、预制场景、_validate_property、internal 子节点、NOTIFICATION_EDITOR_PRE_SAVE、C# 重载。level authoring, WYSIWYG, prefab, data-driven, bake on save, empty scene, audit.","https:\u002F\u002Fgithub.com\u002FMindsMaster\u002Fgodot-claude-code-skills\u002Fblob\u002Fmaster\u002Fskills\u002Fgodot-scene-authoring\u002FSKILL.md",[],[],{"skillNo":83,"name":84,"nameZh":6,"description":85,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":86,"categories":87,"keywords":88,"publishedAt":19},"01M7FBNN4WFN0PHM6P7SDH7V0J","godot-scene-architecture","拆分 Godot 4 场景与组织节点时用。PackedScene 组件复用、节点引用 @onready @export %UniqueName、信号与直接调用的选择、分组 call_group、Autoload 与普通节点、组合与继承、状态机、暂停 process_mode、queue_free 与 is_instance_valid、_ready 顺序、场景切换。scene tree architecture, signals, autoload.","https:\u002F\u002Fgithub.com\u002FMindsMaster\u002Fgodot-claude-code-skills\u002Fblob\u002Fmaster\u002Fskills\u002Fgodot-scene-architecture\u002FSKILL.md",[],[],{"skillNo":90,"name":91,"nameZh":6,"description":92,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":93,"categories":94,"keywords":95,"publishedAt":19},"01M7FBNFF1K8A77X45BDBQCA6E","godot-resources-data","定义游戏数据表 配置 存档 资源加载时用。自定义 Resource class_name @export .tres 与 C# [GlobalClass]、JSON 与 Resource 怎么选、导入时把 JSON CSV 转成 Resource、资源共享与 duplicate local_to_scene、load preload 与线程加载进度条、user:\u002F\u002F 存档、导出后读不到 res:\u002F\u002F 目录。game data, custom resource, save game.","https:\u002F\u002Fgithub.com\u002FMindsMaster\u002Fgodot-claude-code-skills\u002Fblob\u002Fmaster\u002Fskills\u002Fgodot-resources-data\u002FSKILL.md",[],[],{"skillNo":97,"name":98,"nameZh":6,"description":99,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":100,"categories":101,"keywords":102,"publishedAt":19},"01M7FBNB7C2A6XE5E48XH5NC5D","godot-performance","排查卡顿 掉帧 帧率低 内存增长时用，也用于几百个怪物 子弹同屏、CharacterBody 拥挤变慢、每帧重建网格、线程池只用上两三个核、C# 跨界开销。先测再改 Profiler Monitors。不降画面与数量的内置解法 管理器统一驱动、MultiMesh、Server、对象池、空间哈希、WorkerThreadPool 分块、网格局部更新、物理插值、线程加载、着色器编译卡顿、每帧分配。Godot performance, stutter, many entities.","https:\u002F\u002Fgithub.com\u002FMindsMaster\u002Fgodot-claude-code-skills\u002Fblob\u002Fmaster\u002Fskills\u002Fgodot-performance\u002FSKILL.md",[],[]]