Modify Model Variables with Run ID

Hello,

I have run Id’ s for my multiplayer game and want to modify model variables. I am unable to find the relevant documentation neither Adapter API nor REST API. Closes Documentation I found was https://forio.com/epicenter/docs/public/rest_apis/aggregate_run_api/#data-operation.

If someone could share the snippet or point me to the right documentation I’d really appreciate it.

Thanks in advance.

This is in JavaScript, correct? Use the run service in the epicenter js libraries to change the variables. The run service is useful for working with one ore more arbitrary runs.
https://forio.com/epicenter/docs/public/api_adapters/generated/run-api-service/

The RunManager (with an associated Variable Service) is useful for working with the “current run” for a given student.
https://forio.com/epicenter/docs/public/api_adapters/generated/variables-api-service/

In your case, use the run service since you are going to loop through a list of run ids.

var rs = new F.service.Run({
    account: 'acme-simulations',
    project: 'supply-chain-game',
});
rs.save({variables: { a: 23, b: 23 } }, { id: '0000015bf2a04995880df6b868d23eb3d229' });

Note that the “save” method is asynchronous and returns a promise, allowing you to add code that is executed when the save is completed.

Thank you for the reply Will.
This is my snippet of code.

I am running this from the facilitator account and want to update user view based on the value,
I am binding the variable using flow.js like this data-f-showif="Reference Demand Story|is(1, true, ' ')".

This however is not working. Please suggest where I might be going wrong.

We understand you are trying to have the facilitator loop through all the worlds, and set a variable for each world. Here’s how to do that.

// update the runs for all worlds with variables.
// parameter is map, e.g. {"var1": 10, "var2": 20}
function updateVariables(varMap) {
  
  const wa = new F.service.World();
  wa.list().then((worlds) => {
    worlds.forEach((world) => {
      if (world.run) {
        const rm = new F.manager.RunManager(
          {
            run: { model: 'model.eqn'}, 
            strategy: 'use-specific-run', 
            strategyOptions: {
              runId: world.run
            }
          });
        rm.getRun().then(function(run) {
          rm.run.variables().save(varMap);
        });
      }
    });
  });
}

Note that the trick is to use a RunManager with the run strategy “use-specific-run”. Normally the RunManager is used to track the run for the current user, but this run strategy allows you to pass in a run. You can then get the variable service and set the value.