16. Autoplay StoryScript games
When I was a teenager, toy stores had television sets with gaming consoles connected that continuously showed a (very) small piece of a game in action. It was a pretty good way to show what a game is about. I thought about this while also considering how StoryScript can be used for educational purposes. With its support for maps, conversations and multimedia, you could build a very nice interactive story for e.g. a museum. There too, autoplaying (part of) the game could be useful.
So I decided to add support for scripting autoplay sessions. These are the additions I made:
- Optionally show a title screen for the game.
- Transition from the title screen (when used) to autoplaying the game.
- Easy scripting of the autoplay sequence.
- Showing that the game is autoplaying.
To add autoplay to your game, you add a titleScreen section to the setup section of your rules, like this:
setup: {
titleScreen: {
showTitleScreen: true,
transitionDelay: '2',
getDemoMode: getDemoMode
}
}
I called the new section titleScreen because to me it makes more sense to have a title screen without autoplay than vice versa. the getDemoMode property is an object with three properties for you autoplay setup: startDelay, party and steps. The first two are pretty straightforward. You can define the delay before autoplay starts and set up a party (if your game needs a party, a party can also consist of only one character). The steps property is an array of IAutoplayStep. Each of these has an action that should be executed during that step.
To help you to more easily code your game's autoplay, I created the Commands service on the Game object to offer convenient methods to perform game actions like working with combinations, travelling, conversing and working with barriers. An autoplay step looks like this:
{
action: (game: IGame) => game.commands.selectCombination(combination),
delay: 2000
}
As an example, I added a title screen and autoplay to the adventure game demo. You can find the autoplaying demo here and check out the code in the demoMode.ts file in the MyAdventureGame folder of your repository. To completely autoplay the game, this is all the scripting I needed after creating a function to handle the commonalities:
export const getDemoMode = () => {
return <IDemoMode>{
startDelay: 5000,
party: {
characters: [{}]
},
steps: [
...getStep(Combinations.LOOKAT, Fountain),
...getStep(Combinations.TOUCH, Fountain),
...getStep(Combinations.WALK, Corridor),
...getStep(Combinations.LOOKAT, WoundedWarrior),
...getStep(Combinations.TOUCH, Herbs),
...getStep(Combinations.WALK, 'Passage back'),
...getStep(Combinations.USE, Fountain, Flask),
...getStep(Combinations.USE, Water, Herbs),
...getStep(Combinations.WALK, Corridor),
...getStep(Combinations.USE, WoundedWarrior, HealingPotion)
]
};
}
As you can see, the character for this autoplay demo is empty, but I need a character to be able to carry the items in the game.
