array of language-independent variable names; these will be underscorized so the English names can be passed in here. See Util.toName.
array of localized variable names
Optional
opt_name: stringname of this VarsList
if varNames and localNames are different lengths, or contain anything other than strings, or have duplicate values
Private
histRecent history of the simulation state for debugging; an array of copies of the vars array.
Private
history_Whether to save simulation state history.
Private
timeIndex of time variable, or -1 if there is no time variable.
Static
Readonly
DELETEDIf a variable name is 'DELETED' then that variable is not in use and should be ignored.
Static
Readonly
TIMELanguage-independent name of time variable.
Static
Readonly
VARS_Name of event signifying that the set of variables has been modified: variables may have been added or removed, or the name of variables changed.
Adds the given Observer to this Subject's list of Observers, so that the Observer
will be notified of changes in this Subject. An Observer may call Subject.addObserver
during its observe
method.
the Observer to add
Adds the Parameter to the list of this Subject's available Parameters.
the Parameter to add
if a Parameter with the same name already exists.
Add a Variable to this VarsList.
the Variable to add
the index number of the variable
if name if the Variable is 'DELETED'
Add a continguous block of ConcreteVariables.
language-independent names of variables; these will be underscorized so the English name can be passed in here. See Util.toName.
localized names of variables
index index of first ConcreteVariable that was added
if any of the variable names is 'DELETED', or array of names is empty
Notifies all Observers that this Subject has changed by calling observe on each Observer.
An Observer may call addObserver or removeObserver during its observe
method.
a SubjectEvent with information relating to the change
Notifies all Observers that the Parameter with the given name has changed by calling observe on each Observer.
the language-independent or English name of the Parameter that has changed
if there is no Parameter with the given name
Delete several variables, but leaves those places in the array as empty spots that can be allocated in future with addVariables. Until an empty spot is reallocated, the name of the variable at that spot has the reserved name 'DELETED' and should not be used.
index of first variable to delete
number of variables to delete
Protected
getReturns whether broadcasting is enabled for this Subject. See setBroadcast.
whether broadcasting is enabled for this Subject
Whether recent history is being stored, see saveHistory.
true if recent history is being stored
Returns the ParameterBoolean with the given name.
the language-independent or English name of the ParameterBoolean
the ParameterBoolean with the given name
if there is no ParameterBoolean with the given name
Returns the ParameterNumber with the given name.
the language-independent or English name of the ParameterNumber
the ParameterNumber with the given name
if there is no ParameterNumber with the given name
Returns the ParameterString with the given name.
the language-independent or English name of the ParameterString
the ParameterString with the given name
if there is no ParameterString with the given name
Returns the value of the time variable, or throws an exception if there is no time variable.
There are no explicit units for the time, so you can regard a time unit as any length of time, as long as it is consistent with other units. See About Units Of Measurement.
the current simulation time
if there is no time variable
Returns an array with the current value of each variable.
Optional
computed: booleanwhether to include computed variables, see Variable.isComputed; default is false.
an array with the current value of each variable. Computed variables have value of NaN unless requested.
Returns the Variable object at the given index or with the given name
the index or name of the variable; the name can be the English or language independent version of the name
the Variable object at the given index or with the given name
Increments the sequence number for the specified variable(s), which indicates a discontinuity has occurred in the value of this variable. This information is used in a graph to prevent drawing a line between points that have a discontinuity. See Variable.getSequence.
Rest
...indexes: number[]the indexes of the variables to increment; if no index given then all variable's sequence numbers are incremented
Returns index of the Variable, or -1 if not found.
the Variable or name of Variable; the name can be the English or language independent version of the name
integer index number of the variable, or -1 if not found
Prints recent 'history' set of variables to console for debugging.
Prints the n
-th oldest snapshot, where n=1
is the most recent snapshot, n=2
is
the snapshot previous to the most recent, etc.
See saveHistory.
Optional
index: numberthe index of the snapshot to print, where 1 is most recent; if no index is specified, then prints a selected set of recent histories.
the history variables formatted as code to recreate the situation
Removes the Observer from this Subject's list of Observers. An Observer may
call removeObserver
during its observe
method.
the Observer to detach from list of Observers
Removes the Parameter from the list of this Subject's available Parameters.
the Parameter to remove
Saves the current variables in a 'history' set, for debugging, to be able to reproduce an error condition. See printHistory.
Protected
setSets whether this Subject will broadcast events, typically used to temporarily disable broadcasting. Intended to be used in situations where a subclass overrides a method that broadcasts an event. This allows the subclass to prevent the superclass broadcasting that event, so that the subclass can broadcast the event when the method is completed.
whether this Subject should broadcast events
the previous value
Indicates the specified Variables are being automatically computed. See Variable.isComputed.
Rest
...indexes: number[]the indexes of the variables
Sets whether to store recent history, see saveHistory.
true means recent history should be stored
Sets the current simulation time. There are no explicit units for the time, so you can regard a time unit as seconds or years as desired. See About Units Of Measurement.
the current simulation time.
if there is no time variable
Sets the specified variable to the given value. Variables are numbered starting at zero. Assumes this is a discontinous change, so the sequence number is incremented unless you specify that this is a continuous change in the variable. See incrSequence.
the index of the variable within the array of variables
the value to set the variable to
Optional
continuous: booleantrue
means this new value is continuous with
previous values; false
(the default) means the new value is discontinuous with
previous values, so the sequence number for the variable is incremented
if value is NaN
for a non-computed variable
Sets the value of each variable from the given list of values. When the length of
vars
is less than length of VarsList then the remaining variables are not modified.
Assumes this is a discontinous change, so the sequence number is incremented
unless you specify that this is a continuous change in the variable.
See incrSequence.
array of state variables
Optional
continuous: booleantrue
means this new value is continuous with
previous values; false
(the default) means the new value is discontinuous with
previous values, so the sequence number for the variable is incremented
if length of vars
exceeds length of VarsList
Returns a minimal string representation of this object, usually giving just identity information like the class name and name of the object.
For an object whose main purpose is to represent another Printable object, it is
recommended to include the result of calling toStringShort
on that other object.
For example, calling toStringShort()
on a DisplayShape might return something like
this:
DisplayShape{polygon:Polygon{'chain3'}}
a minimal string representation of this object.
Generated using TypeDoc
A set of Variables which represent the current state of a simulation. Variables are numbered from
0
ton-1
wheren
is the number of Variables.VarsList is a Subject and each Variable is a Parameter of the VarsList. This makes the set of Variables available for scripting with EasyScriptParser.
Unlike other Subject classes, VarsList does not broadcast each Variable whenever the Variable changes. And VarsList prohibits adding general Parameters in its addParameter method, because it can only contain Variables.
As a Subject, the VarsList will broadcast the VARS_MODIFIED event to its Observers whenever Variables are added or removed.
Continuous vs. Discontinuous Changes
A change to a Variable is either continuous or discontinuous. This affects how a line graph of the Variable is drawn: DisplayGraph doesn't draw a line at a point of discontinuity. A discontinuity is indicated by incrementing the sequence number of the Variable.
It is important to note that setValue and setValues have an optional parameter
continuous
which determines whether the change of variable is continuous or discontinuous.Here are some guidelines about when a change in a variable should be marked as being discontinuous by incrementing the sequence number:
When a change increments only a few variables, be sure to increment any variables that are dependent on those variables. For example, if velocity of an object is discontinuously changed, then the kinetic, potential and total energy should all be marked as discontinuous.
When dragging an object, don't increment variables of other objects.
When some parameter such as gravity or mass changes, increment any derived variables (like energy) that depend on that parameter.
Deleted Variables
When a variable is no longer used it has the reserved name 'DELETED'. Any such variable should be ignored. This allows variables to be added or removed without affecting the index of other existing variables.
Events Broadcast