The Standard Library
The Gamefic SDK includes a 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
.
Character
Both player characters and non-player characters can be made from the Character
entity.
Room
A physical location in the game world. You can place an entity in a Room
by setting its parent
attribute.
Mygame::Plot.script do
# Put a "thing" and the player inside a room
@room = make Room, name: 'room'
@thing = make Thing, name: 'thing', parent: @room
introduction do |actor|
actor.parent = @room
end
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.
The connect
method connects rooms to each other.
Mygame::Plot.seed do
@forest = make Room, name: 'forest', description: 'A placid forest.'
@lake = make Room, name: 'lake', description: 'The edge of a lake.'
connect @forest, @lake, 'east'
end
Mygame::Plot.script do
introduction do |actor|
actor.parent = @forest
actor.perform :look
end
end
Receptacle
A Thing
that can contain other things. Receptacles can also be enterable
, which means that characters can get inside them.
Mygame::Plot.seed do
@room = make Room, name: 'room'
@cupboard = make Receptacle, name: 'cupboard', parent: @room
@dish = make Item, name: 'dish', parent: @room
@closet = make Receptacle, name: 'closet', enterable: true, parent: @room
end
Mygame::Plot.script do
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
end
Container
A specialized receptacle that can be closed and optionally locked.
MyGame::Plot.seed do
@room = make Room, name: 'room'
@shoebox = make Container, name: 'shoebox', open: false, parent: @room
@key = make Item, name: 'key', parent: @room
@lockbox = make Container, name: 'lockbox', lock_key: @key, locked: true
end
MyGame::Plot.script do
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
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.
Mygame::Plot.seed do
@kitchen = make 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.
)
@sink = make Scenery, name: "sink", description: "Most kitchens have one.", parent: @kitchen
@dish = make Item, name: "plate", description: "A ceramic plate.", parent: @kitchen
end
Mygame::Plot.script do
introduction do |actor|
actor.parent = @kitchen
end
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