Testing a game
An agent can play a game the way a player does, and check what happened.
Press keys
input.set presses or lets go of a key, a mouse button or a gamepad control. It stays that way until set again.
For a stick, give a number from -1 to 1:
input.release_all lets go of everything.
Let time pass
play.run takes frames or seconds. It enters play mode if needed and stays in it. It returns what the game logged meanwhile and how many script errors there were:
Time advances in steps of 1/60 second without waiting for the clock, so a run gives the same result every time.
Read the game's state
lua.run can reach into any script:
It can also set things up, such as placing an enemy in front of the player before testing that shooting works.
Look at it
Then open the image. A passing check does not prove the picture is right.
A whole test
This plays the third person template: walks forward for a second and checks the player moved.
The files in Tests/commands/ in the repository are tests of this kind, run by ctest.
Testing the editor's own window
For what a person does with the editor's window, --ui-script feeds it a scripted mouse and keyboard:
Each step is frame:action. The actions are click x,y, rclick x,y for the right button, move x,y, type text, clear (select all the text in the focused field) and key Name. Positions are in window units.
--expect-selected fails the run unless that entity is selected at the end. A hidden editor never starts another program: it logs what it would have opened.