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

/event-bus

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

Use when setting up decoupled node communication — a global EventBus autoload with typed signals. Not for adding signals to an existing bus

Use this Skill: https://skilld.dev/gh/jame581/godotprompter/event-bus

Nothing lands on disk. Nothing to clean up.

Fork this Skill

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

referencestyped-signals.md

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

← Back to SKILL.md

Typed Signal Parameters

For signals that need to pass multiple related values, prefer a dedicated Resource (strongly typed, Inspector-friendly) over a plain Dictionary (flexible but untyped).

Option A — Resource payload (recommended for structured data)

# combat_event_data.gd
class_name CombatEventData
extends Resource

@export var attacker_id: int = 0
@export var target_id: int = 0
@export var damage_amount: int = 0
@export var damage_type: String = "physical"
@export var is_critical: bool = false
# In event_bus.gd — add the signal:
signal combat_hit(data: CombatEventData)
# Producer
var data := CombatEventData.new()
data.attacker_id   = get_instance_id()
data.target_id     = target.get_instance_id()
data.damage_amount = 25
data.damage_type   = "fire"
data.is_critical   = true
EventBus.combat_hit.emit(data)
# Consumer
func _on_combat_hit(data: CombatEventData) -> void:
    if data.is_critical:
        _show_critical_text(data.target_id, data.damage_amount)
// CombatEventData.cs — Resource-based payload (Inspector-friendly, fully typed)
using Godot;

public partial class CombatEventData : Resource
{
    // long, not int — instance IDs are 64-bit (see the producer below).
    [Export] public long AttackerId  { get; set; }
    [Export] public long TargetId    { get; set; }
    [Export] public int DamageAmount { get; set; }
    [Export] public string DamageType { get; set; } = "physical";
    [Export] public bool IsCritical  { get; set; }
}

// In EventBus.cs — add the signal:
// [Signal] public delegate void CombatHitEventHandler(CombatEventData data);

// Producer
public void FireCombatHit(Node target, int damageAmount, string damageType, bool isCritical)
{
    var data = new CombatEventData
    {
        // GetInstanceId() returns ulong and Godot packs a validator into the high bits, so real
        // IDs exceed int.MaxValue. Casting to int silently drops that and InstanceFromId() on the
        // result will not resolve the object.
        AttackerId   = (long)GetInstanceId(),
        TargetId     = (long)target.GetInstanceId(),
        DamageAmount = damageAmount,
        DamageType   = damageType,
        IsCritical   = isCritical,
    };
    _eventBus.EmitSignal(EventBus.SignalName.CombatHit, data);
}

// Consumer
private void OnCombatHit(CombatEventData data)
{
    if (data.IsCritical)
        ShowCriticalText(data.TargetId, data.DamageAmount);
}

Option B — Dictionary payload (acceptable for prototyping)

# In event_bus.gd:
signal combat_hit(data: Dictionary)

# Producer
EventBus.combat_hit.emit({
    "attacker_id":   get_instance_id(),
    "target_id":     target.get_instance_id(),
    "damage_amount": 25,
    "is_critical":   true,
})

# Consumer — note: no compile-time safety
func _on_combat_hit(data: Dictionary) -> void:
    if data.get("is_critical", false):
        _show_critical_text(data["target_id"], data["damage_amount"])
// In EventBus.cs:
// [Signal] public delegate void CombatHitEventHandler(Godot.Collections.Dictionary data);

// Producer
_eventBus.EmitSignal(EventBus.SignalName.CombatHit, new Godot.Collections.Dictionary
{
    ["attacker_id"]   = (long)GetInstanceId(),
    ["target_id"]     = (long)target.GetInstanceId(),
    ["damage_amount"] = 25,
    ["is_critical"]   = true,
});

// Consumer — every read is an unchecked Variant cast; a renamed key fails at runtime,
// and a wrong .AsX() silently returns default rather than throwing.
private void OnCombatHit(Godot.Collections.Dictionary data)
{
    if (data.TryGetValue("is_critical", out var critical) && critical.AsBool())
        ShowCriticalText(data["target_id"].AsInt64(), data["damage_amount"].AsInt32());
}

C# loses more here than GDScript does: the Resource form above gives compile-time checking and IntelliSense, while this one is untyped both ways across the marshalling boundary.

Prefer Resources for structured, reusable payloads with more than 2–3 fields. Use Dictionary only when prototyping or the shape changes frequently.

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

    This skill provides architectural templates and best practices for implementing an Event Bus pattern in Godot 4.3+. It includes code for GDScript and C#, unit testing instructions, and guidance on avoiding memory leaks. No security issues were identified.

  • 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/event-bus