Holarch

Behavior

Simulation Scripts

JavaScript hooks on actions, ORs, SYNCs 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, SYNC or LOOP; the inspector has Edit Script… (Add Script… on a construct without one).

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 when the action’s Duration is =script(); prompt(p) builds a dialog with p.setTitle(), p.addEnumInput(), addTextInput, addNumberInput and addBooleanInput.
  • Available: print(x) (Console panel), globals.put/get (Script Variables) 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