The Gamefic SDK includes mechanisms for using and distributing shared script libraries. The easiest way to share a library is to publish it as a gem.
A common example of a shared library is
gamefic-standard, which is included with the SDK.
How Libraries Work
A Gamefic library, at its core, is just a gem. It contributes to games by adding its own classes, modules, and/or Gamefic scripts.
Libraries published as gems should follow the naming convention
Authors import libraries with the
require method. The
main.rb script in a new game includes
gamefic-standard by default:
Additional libraries can be included by installing their gems and requiring them.
A Simple Example
You can experiment with libraries by creating one inside a game project.
Go to a project folder or create a new one with
Create a directory named
Add a file
lib/gamefic-example.rbwith the following code:
respond :example do |actor|
actor.tell "This command was provided by gamefic-example."
- Make the following changes to
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'lib')
class Mygame::Plot < Gamefic::Plot
introduction do |actor|
actor.tell "This game includes the gamefic-example library."
Run the game with
rake ruby:run. If you enter EXAMPLE at the command prompt, you should get the message:
This command was provided by gamefic-example.
Creating a Library Gem
gamefic init command has a
--gem option to create a project for a library gem:
$ gamefic init --gem gamefic-example
By default, the gemspec includes
gamefic-standard as a dependency. If you don’t want to require the standard library, you can safely remove it.
Distributing the Library
The simplest way to share the library with other authors is to publish it as a gem. See the RubyGems guide for more information.