Repository navigation
Scripting
Michael Yarichuk edited this page Oct 18, 2026
·
1 revision
dotnet add package RoguelikeToolkit.Entities.Scripting.Jintusing RoguelikeToolkit.Entities.Scripting.Jint;
EntityScripting.Register(); // once at startup, BEFORE spawning templates with script membersWithout this, spawning a template with a script member throws InvalidCastException naming the script type.
[Component]
public class Behavior
{
public EntityScript? OnHit { get; set; }
public EntityComponentScript? Regen { get; set; }
}Components:
Behavior:
OnHit: |
var h = entity.GetComponent(Health);
h.Current -= damage;
entity.SetComponent(Health, h);
Regen: component.Current += amount;using var host = new ScriptHost(new ScriptHostOptions { ReferenceTypes = new[] { typeof(Health) } });
var b = goblin.Get<Behavior>();
b.OnHit!.ExecuteOn(host, ref goblin, ("damage", 4));
b.Regen!.TryExecuteOn<Health>(host, goblin, ("amount", 2));- Scripts are immutable and shared; keep state in components.
- One
ScriptHostper thread/simulation loop (not thread-safe). Scripts themselves are. - Expose component types to scripts via
ScriptHostOptions.ReferenceTypes. - Value-type components come back as copies: write them back with
SetComponent. - Defaults: 500 statements, recursion depth 1024.
TimeoutandMemoryLimitBytesare opt-in (leave memory limit off on IL2CPP).
RoguelikeToolkit.Entities