A Variable whose value is defined by a JavaScript function.

For example, suppose the variable 'position' is at index 0 in the VarsList. This script will create a new variable that gives the position offset by a fixed amount.

var fn = () => varsList.getValue(0) - 5.5
var fnv = new FunctionVariable(varsList, 'position offset', 'position offset', fn);
varsList.addVariable(fnv)

You can then choose that variable to show in a graph or time graph.

Hierarchy (view full)

Implements

Constructors

  • Parameters

    • varsList: VarsList

      the VarsList which contains this Variable

    • name: string

      the name of this Variable; this will be underscorized so the English name can be passed in here. See Util.toName.

    • localName: string

      the localized name of this Variable

    • getter: (() => number)

      A function with no arguments that returns the value of this Variable

        • (): number
        • Returns number

    • Optional setter: ((v) => void)

      An optional function with one argument that sets the value of this Variable

        • (v): void
        • Parameters

          • v: number

          Returns void

    Returns FunctionVariable

Properties

seq_: number = 0

Sequence numbers, to detect discontinuity in a variable, see Variable.getSequence.

varsList_: VarsList

the VarsList which contains this Variable

Methods

  • Name of this SubjectEvent, either the language-independent name for scripting purposes or the localized name for display to user.

    The language-independent name should be the same as the English version but capitalized and with spaces and dashes replaced by underscore, see Util.toName and nameEquals.

    Parameters

    • Optional opt_localized: boolean

      true means return the localized version of the name; default is false which means return the language independent name.

    Returns string

    name of this object

  • Returns the sequence number of this Variable. The sequence number is incremented whenever a discontinuity occurs in the value of the variable. See incrSequence.

    For example, when the variables are set back to initial conditions that is a discontinuous change. Then a graph knows to not draw a connecting line between the points with the discontinuity.

    Another example of a discontinuity: if the value of an angle is kept within 0 to 2*Pi (by just adding or subtracting 2*pi to keep it in that range), when the angle crosses that boundary the sequence number should be incremented to indicate a discontinuity occurred.

    Returns number

    the sequence number of this Variable.

  • Returns whether the value is being automatically computed; setting the value of this Parameter has no effect.

    Examples of automatically computed Parameters: the variables that give the current energy of a simulation. Another example is when the size of a graph's SimView is under control of an AutoScale.

    Returns boolean

    whether the value is being automatically computed

  • Sets the value of this Parameter after converting the given string to the appropriate type (boolean, number or string).

    Parameters

    • value: string

      the value to set this Parameter to, in string form

    Returns void

    Throws

    if the string cannot be converted to the needed type

  • 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'}}
    

    Returns string

    a minimal string representation of this object.

Generated using TypeDoc