44 lines
No EOL
2.6 KiB
HTML
44 lines
No EOL
2.6 KiB
HTML
<!doctype html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>world_kind — Ludic</title>
|
||
<meta name="description" content="The model id of an instance — which kind of thing it is.">
|
||
<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="api.html#ecs">Entities & the ECS</a> <span>›</span> <span class="here">world_kind</span></div>
|
||
<div class="item-head">
|
||
<span class="kind-badge kind-builtin">function</span>
|
||
<h1 id="top">world_kind</h1>
|
||
</div>
|
||
<code class="sig">world_kind(target) -> int</code>
|
||
<div class="desc"><p><code>world_kind</code> returns the model id of a given instance — that is, which kind of thing it is — as an <code>int</code>. Compare the result against ids from <code>world_model_id</code> to branch generically on an instance's kind without knowing it at compile time, the reflection-ABI stand-in for the <code>{Model}</code> tag filter in a static <code>query</code>. It is the natural partner of <code>world_query_next</code> when you walk instances by id and need to tell players from enemies. Pass the instance handle you want to classify.</p></div>
|
||
<div class="params"><h2>Parameters</h2><div class="param" id="param-target"><code class="pname">target</code><span class="pdesc">the model instance to classify, an <code>entity</code> handle</span></div></div>
|
||
<div class="examples"><h2>Example</h2><pre data-lang="ludic">program Classify {
|
||
property Position { column: int = 0, row: int = 0 }
|
||
model Player { Position }
|
||
model Enemy { Position }
|
||
|
||
handler Boot phase Start {
|
||
spawn Hero { Position { column: 2, row: 2 } }
|
||
spawn Grunt { Position { column: 8, row: 2 } }
|
||
}
|
||
|
||
handler Inspect phase Update {
|
||
let enemy_model = world_model_id("Enemy")
|
||
for (position) in query [Position] {
|
||
if world_kind(self()) == enemy_model { Screen.status("found an enemy") }
|
||
}
|
||
}
|
||
}</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> |