NovaScript Introduction

From Nova Documentation
Revision as of 22:42, 3 January 2015 by Novaadmin (Talk | contribs) (Scenarios)

Jump to: navigation, search

All running Nova simulations are expressed in a language called NovaScript. Even in the simplest stock- flow model, you are already writing NovaScript code when you enter expressions for initial Stock values, Flows, and Terms (we’ll refer to these as component definitions). For these models, however, the code is generally restricted to simple numerical expressions. You will see that to express the relationships required of complex models your definitions will necessarily include a broader set of expressions.

NovaScript is an extension of a well-known and widely used language called JavaScript. This means that NovaScript uses JavaScript syntax for all of its code; moreover, any legal JavaScript program is also a NovaScript program. This includes the code used for initial Stock values, Flows and Terms. Fortunately, there are many good sources for learning to program in JavaScript. Please read the introduction to JavaScript contained here before continuing with this section.

A complete Nova model is expressed in NovaScript. You create the program for this model when you click the Capture button. Nova is able to construct the scaffold for your model using the structure of the visual elements placed on the canvas. As author you are expected to provide the details connecting the various components through the component expressions. In systems dynamics models component expressions generally operate solely on numerical data; i.e., they are simple arithmetic expressions.

As you extend your use of Nova into more complex applications the coding used to link components will also become more complex. This complexity manifests along the following dimensions:

  • The data structures used. Simple applications can rely on simple numerical data. For more advanced use you will need to introduce arrays and objects, and may also want to create your own functions.
  • The program structures required. Multi-line computations involving loops and conditionals generally accompany the use of data structures such as arrays and objects.
  • The use of primitive operators. Models using Nova’s aggregating components rely heavily on primops. You will need to become familiar with these primops and how they provide necessary information to the constituents of the aggregators.

What is NovaScript?

As mentioned above, NovaScript is embedded in JavaScript. Precisely, this means that NovaScript is JavaScript with additional functionality and special objects. The concept of extending the JavaScript core with special objects is not new. In fact, we’ve seen that JavaScript itself does this with the Math object, used to bundle together a substantial set of mathematical functions[1]. In order for JavaScript to control the behavior of a Web browser, the JavaScript environment is extended with a Document[2] object that contains fields specifically designed for Web browser functionality.

NovaScript similarly extends JavaScript with a set of object specifically engineered to express the design of Nova. Thus there are Stock, Term and Flow objects corresponding to those components in a visually rendered Nova model. We call these component objects. Moreover, there is a Capsule representing an entire model or submodel, referencing all of its constituent parts. There are also Table, Graph, Slider and Spinner objects for input/output, and a single NovaScript object type, VPlugin, acting as a surrogate for every type of plug-in


The Capsule is one type of simulator . A simulator is a container whose components are programmed to interact, creating a runnable simulation. The other NovaScript simulators are the four aggregating components described in Component Guide 2: Containers. A Capsule can contain Stocks, Flows, Terms, Commands, Codechips, etc., but also any of the simulator types (a chip is just a Capsule contained in a parent Capsule). Aggregator components (called members), however, must be Capsules.

Note that components such as Stocks, Terms and Flows do not contain other components as constituents. We’ll use the term base components to distinguish Stocks, Terms and Flows from simulators such as Capsules, CellMatrices and AgentVectors.

Except for the top level Capsule, every simulator is the component of some other simulator. For example, Capsule A may contain a chip containing an instance of Capsule B. Capsule A may also contain one of the aggregators, and that aggregator will contain instances of Capsule C. We use the terms container and component to describe this relationship. Every simulator in a model has a container except for the top-level Capsule.

In order to actually carry out a simulation, a simulator must be associated with a clock. With two exceptions a simulator’s clock is used by all of its components, so that only a single top-level system clock is required. However, new clocks are introduced with Clocked Chips, and when running in batch mode. See Clocked Chips.

Component Objects and State Objects; the Self property

As mentioned above, components such a Stocks, Terms, Floats; but also simulators such as Capsules, CellMatices, etc. are represented in NovaScript as JavaScript objects called component objects. Component objects provide the computational mechanism for carrying out simulations. As a simulation proceeds each of these objects provide access to its current value through its value() method.

Each type of simulator object provides a way of accessing the component objects of its constituents. In the simplest case, a Capsule points to each of its components by name. CellMatrices, AgentVectors, SimWorlds, NodeNetworks and NetWorlds also have methods that produce the component objects of their constituents. Consequently the complete state of any simulator can be found by traversing its structure to extract the value() at all the Stocks, Flows and Terms.

NovaScript however, provides a simpler approach: each simulator has a Self property that references a special state object, in which base component names are bound to the current values of those components. The values in these state objects change as the simulation progresses. If a simulator is not at the top-level, then the state object of its container is the value of the property Super[3]. One can follow the chain of container state objects all the way to the top-level by using Super, Super.Super, etc.


When you capture a visual model Nova creates a set of special objects called scenarios that define every element of the current project. Each scenario describes either a Capsule, graph, table, cell matrix, or some other complex entity. Since we are actually writing JavaScript, each scenario is in fact a JavaScript object with various fields containing the descriptions of constituent parts. Included are the component definitions that you provide when creating the model. When a project is loaded, these scenarios provide the blueprints for construction the actual NovaScript objects. When a NovaScript program is run, the objects come to life and produce the expected simulation.

For those familiar with object oriented programming, the scenario serves as a class definition for the creation of NovaScript objects. As we shall see below, the Nova Codechip component is a tool for method definition in such a system.


  1. Similarly, there is a JavaScript Date object used to contain date and day-of-week data.
  2. For this reason, the JavaScript Web browser environment is often called the document object model, or DOM.
  3. These names are chosen for historic reasons, and also because they are not likely to conflict with the names of some actual components.