ludic/annot-toserver.html
2026-09-17 22:10:03 +00:00

44 lines
No EOL
2.8 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>@ToServer — Ludic</title>
<meta name="description" content="A remote event sent from a client to the server — a client→server request.">
<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#annotations">Annotations</a> <span>›</span> <span class="here">@ToServer</span></div>
<div class="item-head">
<span class="kind-badge kind-annotation">annotation</span>
<h1 id="top">@ToServer</h1>
</div>
<code class="sig">@ToServer event Name { … }</code>
<div class="desc"><p><code>@ToServer</code> marks an <code>event</code> as a directional remote event that travels from a client up to the authority — an RPC, expressed as the ordinary event bus with a direction flag rather than a new concept. At an <code>emit</code> site the event's POD payload is serialized as an event id followed by its packed fields and sent through the transport seam toward the server; it does <b>not</b> run locally. On the far side, draining the transport (the runtime's pump) re-emits it into the normal <code>@On</code> dispatch, so a <code>@Server @On(Name)</code> handler picks it up. Use it for player intent — a move request, a fire command — that the authority must validate before it affects the world. Its mirror is <code>@ToClients</code>, which broadcasts the other way.</p></div>
<div class="examples"><h2>Example</h2><pre data-lang="ludic">program FireRequest {
property AmmoLog { shots_fired: int = 0 }
model Turret { AmmoLog }
@ToServer event Fire { direction: int = 0 } # client -&gt; server request
@Server @On(Fire) handler HandleFire { # authority validates and applies
for (AmmoLog) in query [AmmoLog, {Turret}] {
AmmoLog.shots_fired = AmmoLog.shots_fired + direction
}
}
entry {
spawn Turret { AmmoLog { shots_fired: 0 } }
emit Fire(direction: 1) # serialized onto the wire, not run locally
}
}</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>