43 lines
No EOL
2.4 KiB
HTML
43 lines
No EOL
2.4 KiB
HTML
<!doctype html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>world_count — Ludic</title>
|
||
<meta name="description" content="The total number of live model instances in the world.">
|
||
<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_count</span></div>
|
||
<div class="item-head">
|
||
<span class="kind-badge kind-builtin">function</span>
|
||
<h1 id="top">world_count</h1>
|
||
</div>
|
||
<code class="sig">world_count() -> int</code>
|
||
<div class="desc"><p><code>world_count</code> returns the total number of live model instances in the world, as an <code>int</code> — a quick census without walking the world yourself. It takes no arguments and counts every spawned instance regardless of which properties it carries, so it is handy for a mod or debug overlay that wants a running tally of everything alive using the reflection ABI rather than a <code>query</code> loop. To resolve names to numeric ids for the other reflection calls, see <code>world_prop_id</code>; to read a specific instance's fields by id, see <code>world_get</code>.</p></div>
|
||
|
||
<div class="examples"><h2>Example</h2><pre data-lang="ludic">program Census {
|
||
property Position { column: int = 0, row: int = 0 }
|
||
model Enemy { Position }
|
||
|
||
handler SpawnEnemies phase Start {
|
||
spawn Enemy { Position { column: 3, row: 3 } }
|
||
spawn Enemy { Position { column: 9, row: 3 } }
|
||
}
|
||
|
||
handler DrawWorld phase Render {
|
||
Screen.clear(Color.MidnightBlue)
|
||
let alive = world_count()
|
||
Screen.draw_number(x: 8, y: 8, value: alive, color: Color.Gold, scale: 2)
|
||
Screen.show()
|
||
}
|
||
}</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> |