Playing a game by script (Ferretic)
Skill ferret-ferretic · download all skills · SKILL.md
When to use#
Behaviour checked by playing, where timing or state matters: a race, a jump from a run-up, a lever then a door, an AI reaching a place, a balance change. Arithmetic on paper is no check, nor are keys pressed one tool call at a time (real time passes between). A Ferretic program runs inside the fixed step: the same program on the same game gives the same run.
The model#
test.run {source | file}plays a program in the running game and returns its report:id,status,expectations, the failures' number and the first one (line, code, message with the compared values),log(last values), with RUNS asummary, and the sizes of the tables; read the tables (samples,log,prints,failures) withtest.rows {id, table, offset?, count?}. A run has no limit of its own; any number may run at once. The game is paused at the end; held actions are let go.- The program goes on until it WAITs; then game steps pass. Names: an entity's id or name, or a node's name. Values only the game's code knows:
world.expose('rpm', () => car.rpm)in the game,GAME("rpm")in the test. Events:WAIT EVENT,ON EVENT. - Tests belong to the project:
tests/<what>.ferretic, run withviewer_command test.run {file}; in a checkout,ferret scene <example> --test <file>. - Probes answer facts without a picture:
INVIEW VIEWSHARE VISIBLE OCCLUDER COUNT ONGROUND HEIGHT ERRORS(probe.*).
Steps#
input.actions(what the game binds) andscene.entities(names). If the check needs a value only the game's code knows, addworld.expose(...)for it in the game's code (it costs nothing when no test reads it).- Write the test as a file in
tests/, one behaviour a file, with EXPECTs that say in words what must hold. viewer_restart, thenviewer_command test.run {file}. Read the failures and the values; for motion,SAMPLE EVERYand read the table (test.rows); for looks,SHOTandtest.shot.- Change the game, run the same file again, compare. For anything random,
RUNS 5and readsummary. - Keep the tests that guard what was asked; after a change run the test of what changed.
The language#
reference/ferretic.md has all of it; test.help gives one page. The shape of a test:
SAMPLE EVERY 0.25 s z = POS("car").z, rpm = GAME("rpm")
PRESS throttle
PARALLEL ANY
WAIT EVENT "race:finish"
AND
DO
WAIT UNTIL GAME("rpm") >= 7000
TAP shiftUp
LOOP
END PARALLEL
LOG time = TIME
EXPECT TIME < 14 s, "the quarter mile in under 14 s"
Check afterwards#
The report's status is passed and each EXPECT you rely on is counted in expectations.passed; the numbers in log and samples are the ones the request is about (a time, a distance, a speed), not only "no error". A failing test says what failed in its message; a test that cannot fail checks nothing.
What usually goes wrong#
no action "x": the names are the game's actions (input.actions), not keys.- A value only the game's code knows is not exposed:
GAME("rpm")says which names are; addworld.exposein the game. - A run that does not end: a WAIT UNTIL that never comes true, or a loop that never WAITs (it holds the game).
test.stateshows where it is;test.stopends it; a WAIT with TIMEOUT and an EXPECT on TIMEDOUT makes such a case a failure instead. - Comparing two runs of a game that uses its own random numbers: use
RUNS nand the summary, not one run. - Leaving the game paused: the report says
paused;world.pause {paused: false}orviewer_restartbefore playing by hand.
Files#
reference/ferretic.md— Ferretic, the engine's BASIC-like language for playing a game by script: statements, waits, the game's actions and state, checks, tables, the test.* commands and tests kept in a project.reference/commands.md— The debug command channel: how a tool, the inspector or an AI agent drives a running game, and the commands each package registers.reference/api-ferretic.md— every export of@ferret/ferreticwith signature and doc commentreference/api-inspector.md— every export of@ferret/inspectorwith signature and doc commentreference/api-core.md— every export of@ferret/corewith signature and doc commentreference/api-core-2.md— every export of@ferret/corewith signature and doc commentreference/commands.md— 64 commands of these packages with their arguments