Gamefic

Adventure Games and Interactive Fiction

Queries

Gamefic queries provide a way to access entities with various contexts and requirements. Response arguments use them to match commands to entities that qualify for the resulting action.

anywhere(*args)

Create a response query that searches for entities anywhere in the game.

respond :find, anywhere do |actor, thing|
  actor.tell "There's something called #{a thing} somewhere in the game, but not necessarily in your vicinity."
end

available(*args)

Create a response query that searches for entities that are currently available to the actor. An entity is considered available if it shares the actor’s parent or is accessible through a child or sibling.

respond :kick, available(Item) do |actor, item|
  # ...
end

parent(*args)

Create a response query that checks the command’s argument against the actor’s parent.

construct :auditorium, Room, name: 'auditorium'

respond :verify, parent(auditorium) do |actor, room|
  # Players will see this message in response to "verify auditorium" if the
  # auditorium is their current parent.
  actor.tell "Yes, you're in #{the auditorium}."
end

children(*args)

Create a response query that checks the command’s argument against the actor’s children.

respond :use, children do |actor, thing|
  actor.tell "You're allowed to use #{the thing} because it a direct child in your inventory."
end

descendants(*args)

Create a response query that checks the command’s argument against the actor’s descendants (i.e., children and granchildren).

respond :use, descendants do |actor, thing|
  actor.tell "You're allowed to use #{the thing} because it a descendant in your inventory."
end

siblings(*args)

Create a response query that checks the command’s argument against the actor’s siblings (e.g., entities that share the actor’s parent).

respond :use, siblings do |actor, thing|
  actor.tell "You're allowed to use #{the thing} because it's in ths same room with you."
end

myself(*args)

Create a response query that checks the command’s argument against the actor itself.

respond :kick, myself do |actor, _|
  actor.tell "You kick yourself."
end

plaintext(arg = nil)

Create a response query that performs a plaintext search. The argument can be a String or a RegExp. If no argument is provided, it will match any text it finds in the command. A successful query returns the corresponding text instead of an entity.

respond :say, plaintext do |actor, text|
  actor.tell "You say: #{text}."
end

integer()

Create a response query that accepts a whole number as an argument. A successful query returns the corresponding integer instead of an entity.

respond :do, integer do |actor, number|
  actor.tell "You want to do something #{number} times."
end

Next: Creating custom scenes