The game language, and the motion language in it
Skill ferret-motion · download all skills · SKILL.md
When to use#
A scene's logic is written here, not in the scene's TypeScript: rules, state, who reacts to what, entities with their own state. Motion programs say what happens over time. TypeScript is for externs, what the language cannot say.
Steps#
- The game installs it:
installGame(world, { sensors, effects, motion })from@ferret/dataflow; its files arelogic/*.fgl, named in the code so they are packed. TS/JS:(extern wave-height :from "logic/sea.ts" :kind pure ...); the build connects the file by itself, it exportswaveHeight; callable in streams and motion programs. - Forms:
def,pre/fby,defflow,defn; clockswhen merge every every-s event;defkind :fieldswithset-field send collect query nearest spawn despawn;extern;defmotion,(motion name); scenegame level entity link. - Sensors
time dt step pressed axis position exposed, effectorsemit command; others the game gives. - Commands:
game.checkbefore loading,game.load,game.run; change the running game withedit.game.set(no build, state kept); look withgame.eval,game.trace,game.entities,game.graph. - A missing mechanism: a module in
logic/<mechanism>/with its parameters, externs and own test (reference/game-language.md).
Motion programs#
seq par race for while guard repeat loop on states, wait wait-until wait-event, units 30rpm 90deg 0.4s. Alone: new MotionRuntime({ seed, budget }), rt.load, rt.run, rt.tick(dt) each fixed step; p.state(), p.snapshot().
Check afterwards#
game.check is ok; the mechanism's test passes (headless, or a Ferretic test with WAIT EVENT and game.eval); game:error never came.
What usually goes wrong#
- A statement with only constants runs every step: put a value on a clock.
- A value that depends on itself without
preis refused; streams of two clocks needwhenormerge. - A field written this step reads as before until the next; mail arrives the next step.
- A
.fglundersrc/, or one the code does not name, is not in the package. :fromis a path from the project's root; a file not found there must come frominstallGame(world, { externs }).- A motion loop without
waithits the budget; adefncannot wait: usedefmotion. - A long list: ask with
{offset, count}.
Files#
reference/game-language.md— The language a scene's logic is written in: streams stepped with the world, kinds of entities with fields and mail, motion programs, TypeScript externs, scenes as forms, the game.* commands and changing a running game without a build.reference/motion.md— physics/motion.mdreference/api-dataflow.md— every export of@ferret/dataflowwith signature and doc commentreference/api-motion.md— every export of@ferret/motionwith signature and doc commentreference/commands.md— 17 commands of these packages with their arguments