Start Scripting:Events
We only fire a few events, all at the beginning and end of a turn:
inputEnter
, inputParseBegin
,
inputParseComplete
, and
inputQueueNext
(which fires between queued inputs). Authors can hook into these to run custom
code. For example, you could write a series of random in-game background
events tied to specific Rooms, to print additional
text to the Display after parsing has completed.
Example:
MyGame.reactor.addEventListener('inputParseComplete', function()
{
var random = Math.random() * 100;
switch (MyGame.getCurrentRoom().name)
{
case "Frigid Wastes":
if( random < 10 )
{
MyGame.print(
"You're struck by a flash of blinding light as
sunlight reflects off the packed ice.", "random"
);
}
break;
case "Desert Wastes":
if( random > 5 && random < 10 )
{
MyGame.print(
"Heat haze shimmers off the distant dunes.", "random"
);
}
else if( random > 10 && random < 15 )
{
MyGame.print(
"You feel the sand shift beneath your feet.", "random"
);
}
break;
}
});
prescripts and postscripts prescripts fire after player has entered input but
before input is parsed raw input is passed author can use this opportunity to
completely override the parser
DevGame.createPreScript({ "turtle thinks": (input) => { console.warn(`preScript: turtle thinks ${input}`); DevGame.print(`preScript: Roger the turtle considers ${input}. `); }, });postscripts fire after inputParseComplete, or end of turn actions taken here will have no impact on the turn's parsing
DevGame.createPostScript({ "turtle thinks": (params) => { if ("object" === typeof params) { Object.entries(params).forEach(([id, value]) => { console.warn(`postScript: turtle thinks ${id} ${value}`); }); } DevGame.print("postScript: Roger the turtle considers his options. "); }, });