forio Toggle navigation

World Manager

As discussed under the World API Adapter, a run is a collection of end user interactions with a project and its model. For building multiplayer simulations you typically want multiple end users to share the same set of interactions, and work within a common state. Epicenter allows you to create "worlds" to handle such cases.

The World Manager provides an easy way to track and access the current world and run for particular end users. It is typically used in pages that end users will interact with. (The related World API Adapter handles creating multiplayer worlds, and adding and removing end users and runs from a world. Because of this, typically the World Adapter is used for facilitator pages in your project.)

Using the World Manager

When you instantiate a World Manager, the world's account id, project id, and group are automatically taken from the session (thanks to the Authentication Service).

Note that the World Manager does not create worlds automatically. (This is different than the Run Manager.) However, you can pass in specific options to any runs created by the manager, using a run object.

For example:

var wMgr = new F.manager.WorldManager({
    account: 'acme-simulations',
    project: 'supply-chain-game',
    run: { model: 'supply-chain.py' },
    group: 'team1'
});

wMgr.getCurrentRun();

Constructor options

Required? Name Type Description
  group string The group name to use for filters / new runs
Yes run object Options to use when creating new runs with the manager, e.g. run: { files: ['data.xls'] }. See RunService for details.
Yes run.model string The name of the primary model file for this project.
  account string The account id. In the Epicenter UI, this is the Team ID (for team projects) or User ID (for personal projects). Defaults to undefined. If left undefined, taken from the URL.
  project string The project id. Defaults to undefined. If left undefined, parsed from the URL.
  token string For projects that require authentication, pass in the user access token (defaults to undefined). If the user is already logged in to Epicenter, the user access token is already set in a cookie and automatically loaded from there. (See more background on access tokens). @see Authentication API Service for getting tokens.
  transport JQueryAjaxOptions Options to pass on to the underlying transport layer. All jquery.ajax options are supported.
  server object
  server.host string The value of host is usually the string api.forio.com, the URI of the Forio API server. This is automatically set, but you can pass it explicitly if desired. It is most commonly used for clarity when you are hosting an Epicenter project on your own server
  server.protocol https / http Defaults to https

Methods

getCurrentWorld([userId, groupName])

Returns the current world (object) and an instance of the World API Adapter.

Parameters

Required? Name Type Description
  userId string The id of the user whose world is being accessed. Defaults to the user in the current session.
  groupName string The name of the group whose world is being accessed. Defaults to the group for the user in the current session.

Example

wMgr.getCurrentWorld()
    .then(function(world, worldAdapter) {
        console.log(world.id);
        worldAdapter.getCurrentRunId();
    });

getCurrentRun([model])

Returns the current run (object) and an instance of the Run API Service.

Parameters

Required? Name Type Description
  model string The name of the model file. Required if not already passed in as run.model when the World Manager is created.

Example

wMgr.getCurrentRun('myModel.py')
    .then(function(run, runService) {
        console.log(run.id);
        runService.do('startGame');
    });