Basic Scripting:Prescripts & Postscripts
Prescripts and Postscripts
game.createPreScript() and
game.createPostScript() are methods you can use to have your game
call custom functions at the beginnings and ends of every turn.
game.createPreScript()
Prescript functions fire after the player has entered input but before the input is parsed. They receive the player's raw input as a parameter. Author's can use this opportunity to completely override the parser. The following example will print the player's input back to them on every turn as an echo, before going on to handle the turn normally.
MyGame.createPreScript({
"echo": (input) => {
MyGame.print(`Your words echo back from the cave walls: ${input} `);
},
});
Authors can set prescripts to end the turn preemptively, simply by returning
null or false. For example, imagine that an author
wants to run custom logic to check a special condition to determine whether a
player can perform an action; if not, the author would like to end the turn.
The following example will end the turn.
MyGame.createPreScript({
"mute": (input) => {
if(MyGame.getPlayer().$is("mute")){
MyGame.print(`It's useless. No one can hear {us}. `);
return false;
}
},
});
To remove a prescript you have previously set, use
game.removePreScript().
MyGame.removePreScript("echo");
MyGame.removePreScript("mute");
game.createPostScript()
Postscript functions are called at the very end of a turn, after completing display updates, area events, intervals, and idling NPCs. Actions taken here will have no impact on the turn's parsing, which is complete at this point, but can be used to print to the display or run custom code.
MyGame.createPreScript({
"cat watches": function () {
if(MyGame.$("cat").$is("present")){
let msg = `The cat silently watches your actions. `;
MyGame.print(msg);
}
},
});
To remove a postscript you have previously set, use
game.removePostScript().
MyGame.removePostScript("cat watches");