Gamefic

Adventure Games and Interactive Fiction

Customizing Scenes

by Gamefic on February 1, 2017

The latest updates to Gamefic include a new scene architecture to simplify customization. Authors can specify code blocks for the scene's beginning and ending, customize the prompt, and more.

In Gamefic, a Scene is an object that manages the events of every game's turn. Each scene has a start and a finish. The start gets executed at the beginning of the turn. The finish gets executed after the game receives user input. The default scene, Active, performs the input as a game command. In custom scenes, the author determines how to handle the input.

There are several specialized scenes included in the library. Pause stops the game until the user presses enter. MultipleChoice provides a list of options and requires the user to select one to continue. YesOrNo requires a valid answer.

Plots provide helper methods for creating scenes. Here's a simple example of a multiple choice scene:

@pick_a_color = multiple_choice 'red', 'green', 'blue do |actor, data|
  actor.tell "You chose #{data.selection}."
  actor.cue default_scene
end

The block given to multiple_choice gets executed at the end of the turn, after the user has made a selection. The scene will not continue without a valid choice.

Use the cue method to select a character's scene by its key. This example will prompt the user for a color at the start of the game:

introduction do |actor|
  actor.cue @pick_a_color
end

Here's an example of a custom scene that prompts the user for a name:

@ask_for_name = scene do |scene|
  scene.on_start do |actor, data|
    data.prompt = "What's your name?"
  end
  scene.on_finish do |actor, data|
    actor.name = data.input
    actor.tell "Hello, #{actor.name}!"
    actor.cue default_scene
  end
end

Note the actor.cue call at the end of the on_finish block. The default_scene method returns the standard scene for executing player commands. Most scenes require you to specify what scene to start next. If you don't, the current scene will repeat itself. (The exception is the pause helper, which will automatically switch to default_scene if no other scene was specified.)

You can also customize other scene types by specifying its class in the scene method:

@pick_a_color = scene Scene::MultipleChoice do |scene|
  scene.on_start do |actor, data|
    data.options.push 'red', 'green', 'blue'
    data.prompt = 'Which color?'
    data.invalid_message = 'It has to be from the list.'
  end
  scene.on_finish do |actor, data|
    actor.tell "You chose #{data.selection}!"
    actor.description = "You're wearing a #{data.selection} shirt."
    actor.cue default_scene
  end
end

Using scenes gives you complete control over the play style. You can implement pure CYOA with nothing but multiple-choice scenes or make a hybrid that switches between CYOA and parser. Combined with Gamefic's world model, the possibilities are exhaustive.