38 lines
No EOL
2.1 KiB
HTML
38 lines
No EOL
2.1 KiB
HTML
<!doctype html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>World.despawn — Ludic</title>
|
||
<meta name="description" content="Despawn an entity by id — runs its @OnDespawn hooks and frees the slot.">
|
||
<link rel="stylesheet" href="base.css">
|
||
<link rel="stylesheet" href="docs.css">
|
||
</head>
|
||
<body>
|
||
<header class="nav"><div class="wrap nav-in"><a class="brand" href="index.html"><span class="logo">L</span> Ludic</a><button class="nav-toggle" aria-label="Toggle menu" aria-expanded="false">☰</button><nav class="nav-links"><a href="index.html">Home</a><a href="api.html">API Reference</a><a class="nav-cta" href="https://git.workshopsoft.io/workshopsoft/ludic">Source ↗</a></nav></div></header>
|
||
<main class="wrap item">
|
||
<div class="crumbs"><a href="api.html">API Reference</a> <span>›</span> <a href="ns-world.html">World</a> <span>›</span> <span class="here">World.despawn</span></div>
|
||
<div class="item-head">
|
||
<span class="kind-badge kind-method">method</span>
|
||
<h1 id="top">World.despawn</h1>
|
||
</div>
|
||
<code class="sig">World.despawn(entity)</code>
|
||
<div class="desc"><p>Despawns an entity by id: it runs the entity's model <code>@OnDespawn</code> hook (with reason <code>Despawned</code>), sweeps any entity-scoped event listeners, and frees the slot back to the pool for reuse — the reflective, by-id form of the <code>despawn</code> statement. Use it from a system that has an entity id in hand (the engine world-bounds kill policy uses it, #84) or wherever you would write <code>despawn e</code> but only have the id.</p></div>
|
||
|
||
<div class="examples"><h2>Example</h2><pre data-lang="ludic">program Demo {
|
||
property Mob { hp: int = 0 }
|
||
model M { Mob }
|
||
entry {
|
||
spawn M { Mob { hp: 1 } }
|
||
let pm = World.prop_id("Mob")
|
||
let e = World.query_next(pm, 0)
|
||
World.despawn(e)
|
||
print(World.query_next(pm, 0)) # -1 — none left
|
||
}
|
||
}</pre></div>
|
||
|
||
<a class="back" href="api.html">← All symbols</a>
|
||
</main>
|
||
<script src="ludic-highlight.js"></script>
|
||
<script>Ludic.highlightAll(); Ludic.installCards(); Ludic.flashTarget();</script>
|
||
</body></html> |