39 lines
No EOL
2.7 KiB
HTML
39 lines
No EOL
2.7 KiB
HTML
<!doctype html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>world_spawn — Ludic</title>
|
||
<meta name="description" content="Spawn an instance of a model chosen by numeric id at runtime.">
|
||
<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_spawn</span></div>
|
||
<div class="item-head">
|
||
<span class="kind-badge kind-builtin">function</span>
|
||
<h1 id="top">world_spawn</h1>
|
||
</div>
|
||
<code class="sig">world_spawn(model) -> entity</code>
|
||
<div class="desc"><p><code>world_spawn</code> creates a new instance of a model chosen by numeric id and returns its <code>entity</code> handle — the reflection-ABI counterpart of the static <code>spawn Label { … }</code>. Because the model is given as an id (from <code>world_model_id</code>) rather than a name written in source, a mod or tool can decide <b>at runtime</b> which kind to create. The new instance is seeded exactly as the static spawn would seed it — every property in the model attached with default field values — after which you can set fields with <code>world_set</code>. Use the ordinary <code>spawn</code> statement in normal handler code; reach for <code>world_spawn</code> when the kind is data, not a literal.</p></div>
|
||
<div class="params"><h2>Parameters</h2><div class="param" id="param-model"><code class="pname">model</code><span class="pdesc">the model id to instantiate, from <code>world_model_id</code></span></div></div>
|
||
<div class="examples"><h2>Example</h2><pre data-lang="ludic">program Reinforcements {
|
||
property Position { column: int = 0, row: int = 0 }
|
||
model Enemy { Position }
|
||
|
||
handler Reinforce phase Update {
|
||
if Input.key() == ' ' {
|
||
let enemy_model = world_model_id("Enemy")
|
||
let new_enemy = world_spawn(enemy_model)
|
||
Screen.status(string(new_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> |