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 returnstrueto continue);duration()returns the duration;prompt(p)builds a dialog withp.setTitle(),p.addEnumInput(),addTextInput,addNumberInputandaddBooleanInput.- Available:
print(x)(Console panel),globals.put/get(Global Tracker) and theSimAPI: 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.