Gamefic

Adventure Games and Interactive Fiction

The Standard Library

The Gamefic SDK includes a gamefic-standard library that provides lots of useful components for game worlds.

Entities

The standard library defines ten types of entities:

  • Thing
    • Character
    • Fixture
    • Item
    • Portal
    • Receptacle
      • Container
    • Room
    • Scenery
      • Rubble
    • Supporter

Thing

All other entity types extend from Thing.

(Internally, Thing is just an alias for Gamefic::Entity.)

Character

Both player characters and non-player characters can be made from the Character entity.

(Internally, Character is just an alias for Gamefic::Actor.)

Room

A physical location in the game world. You can place an entity in a Room by setting its parent attribute.

# Put a "thing" and the player inside a room

construct :room, Room, name: 'room'
make Thing, name: 'thing', parent: room

introduction do |actor|
  actor.parent = room
end

Fixture

An entity that is not intended to be movable or portable by characters, similar to how Inform can define an object to be “fixed in place.”

Item

An entity that characters can pick up with a command like take item.

Note: any entity can be made portable by setting its portable attribute, but Items are portable by default.

Portal

A Portal provides a passage between rooms. They can be named using ordinal directions (e.g., “north” and “south”) or simply by their destination.

construct :forest, Room, name: 'forest', description: 'A placid forest.'
construct :lake, Room, name: 'lake', description: 'The edge of a lake.', west: forest

introduction do |actor|
  actor.parent = forest
  actor.perform 'look around'
end

Receptacle

A Thing that can contain other things. Receptacles can also be enterable, which means that characters can get inside them.

construct :room, Room, name: 'room'
make Receptacle, name: 'cupboard', parent: room
make Item, name: 'dish', parent: room
make Receptacle, name: 'closet', enterable: true, parent: room

introduction do |actor|
  actor.parent = room
  actor.tell 'You can put the dish in the closet or the cupboard.'
  actor.tell 'You can get inside the closet but not the cupboard.'
end

Container

A specialized receptacle that can be closed and optionally locked.

construct :room, Room, name: 'room'
construct :shoebox, Container, name: 'shoebox', open: false, parent: room
construct :key, Item, name: 'key', parent: room
make Container, name: 'lockbox', lock_key: key, locked: true

introduction do |actor|
  actor.parent = room
  actor.tell "You can open and close the shoebox."
  actor.tell "You can unlock the lockbox with the key."
end

Scenery

The default behavior for most entities is to list them when the player examines the room:

> look around

Kitchen

You're in a kitchen.

You see a sink.

Scenery, on the other hand, is an entity that can be examined but does not get listed.

construct :kitchen, Room,
          name: "kitchen",
          description: %(
            You're in a kitchen. The sink won't be included in the list of visible entities, but you can
            still examine it.
          )
make Scenery, name: "sink", description: "Most kitchens have one.", parent: kitchen
make Item, name: "plate", description: "A ceramic plate.", parent: kitchen

introduction do |actor|
  actor.parent = kitchen
end

Result:

> look around

Kitchen

You're in a kitchen. The sink won't be included in the list of visible entities, but you can still examine it.

You see a plate.

> examine sink

Most kitchens have one.

Other entities can also be excluded from the list of visible entities by setting its itemized attribute to false.

Rubble

Scenery with slightly modified action responses. As a general guideline, Scenery is something that can’t be carried,
like a wall or the sky; and Rubble is something that might appear to be portable but is otherwise useless, like trash or debris.

Supporter

Similar to a Receptacle, except you put things “on” a Supporter instead of “in” it.

Next: Creating custom commands