Index of every page on this site: llms.txt
All skills
jame581 avatar

/gdscript-advanced

@426e8ab
by Jan Mesarčjame581/godotprompter979 stars
63
Run it yourself

Use when writing production-grade GDScript — performance idioms, metaprogramming, @tool lifecycle, async pitfalls, and signal/Callable trade-offs

Use this Skill: https://skilld.dev/gh/jame581/godotprompter/gdscript-advanced

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesmetaprogramming-recipes.md

≈628 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Metaprogramming Recipes

Reference for skills/gdscript-advanced/SKILL.md — Callable patterns, dynamic dispatch, and modding security.

← Back to SKILL.md


1. Callable as strategy

A common pattern: pass a behavior as data.

class_name Sorter

static func sort_by(items: Array, key: Callable) -> Array:
    items.sort_custom(func(a, b): return key.call(a) < key.call(b))
    return items

# Usage:
var by_health := Sorter.sort_by(enemies, func(e): return e.health)
var by_distance := Sorter.sort_by(enemies, func(e): return e.global_position.distance_to(player.global_position))

2. Bind for partial application

func damage_target(target: Node, amount: int) -> void:
    target.take_damage(amount)

# Make a Callable that always damages this player for 25:
var damage_player_25: Callable = damage_target.bind(player, 25)

# Then somewhere else, call without arguments:
damage_player_25.call()

3. Modding-safe RPC dispatch

Never call user-provided method names directly. Allowlist them.

const MOD_RPC_ALLOWLIST: PackedStringArray = [
    "on_item_pickup",
    "on_enemy_killed",
    "on_quest_complete",
]

func dispatch_mod_event(event_name: String, args: Array) -> void:
    if event_name not in MOD_RPC_ALLOWLIST:
        push_warning("Mod tried to call disallowed event: %s" % event_name)
        return
    for mod in active_mods:
        if mod.has_method(event_name):
            mod.callv(event_name, args)

4. call_deferred for thread/signal safety

# Inside a physics callback (body_entered etc.) the physics state is locked:
func _on_collision(other: Node) -> void:
    $CollisionShape2D.disabled = true                 # error: "Can't change this state while flushing queries"
    $CollisionShape2D.set_deferred("disabled", true)  # safe — applied at the end of the frame
    other.queue_free()                                # already safe — queue_free() is deferred

# From a worker thread, hand results to the main thread:
func _on_thread_done(result: Variant) -> void:
    _apply_result.call_deferred(result)

func _apply_result(result: Variant) -> void:
    pass  # touch the scene tree here, on the main thread

5. Callable lifecycle pitfall

var _callbacks: Array[Callable] = []

func register(cb: Callable) -> void:
    _callbacks.append(cb)

# Later:
func _exit_tree() -> void:
    _callbacks.clear()  # Drop captures so freed objects don't leak references.

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts7d3 checks · Risk SAFE
  • Gen Agent Trust Hub7d

    The skill is a set of technical guidelines for advanced Godot Engine development. It contains no malicious code, external dependencies, or security risks. In fact, it explicitly teaches security best practices, such as allowlisting method names when using dynamic dispatch to prevent potential exploits in game modding or networking.

  • Socket7d

    No alerts

  • Snyk7d

    Risk: LOW · No issues

Signed by skilld at 426e8ab. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 6 days ago.

Activeupdated last week

README badge

README badge for jame581/godotprompter/gdscript-advanced