Holarch

Behavior

Simulation Scripts

JavaScript hooks on actions, ORs and LOOPs that set durations, decide branches and track values during a simulation.

Where to find it

  • In an Action Diagram, select an action, OR or LOOP; the inspector has Edit Action Script….

Main actions

  • onStart() runs when the action starts; onEnd(response) when it ends (an OR returns the branch name, a LOOP returns true to continue); duration() returns the duration; prompt(p) builds a dialog with p.setTitle(), p.addEnumInput(), addTextInput, addNumberInput and addBooleanInput.
  • Available: print(x) (Console panel), globals.put/get (Global Tracker) and the Sim API: getEntityById / ByGlobalId / ByName / ByNumber, getEntitiesByName / ByNumber, getIOValueById…, getAmount…, getResourceByName, setResourceById / ByGlobalId / ByName, getCurrentCost, getCurrentTime. Entities expose getId, getGlobalId, getName, getNumber, getDescription and attributes.

Sandbox and trust

Scripts run in a separate worker with a read-only copy of the model, with no access to the page, your projects, files, browser storage or the network. A script call that runs longer than 8 seconds stops the simulation. Before a model runs scripts that came from somewhere else (an imported or opened file, a collaborator), the Simulator lists them and asks first; Show the scripts reviews them. Tab in the editor inserts two spaces.

Tips

    Related

    Simulator