Please enable JavaScript to view this site.

Vensim Help

There are a number of JavaScript functions provided to you so that you can interact with the WASM file that Vensim generates.

 

 

 

 

function SetConstant(strParameter, fValue)

 

This sets a constant internally to the Vensim model.

 

Return value

The return value is an integer, 1 indicates the function has succeeded, 0 indicates an error.

 

Example

var nResult = SetConstant(“Varname[subelement]”,3.141)

 

 

function GetVariableIndex(strParameter)

 

Internally, each parameter has an ID number, this function allows you to find the ID number of a variable.

 

Return value

The return value is an integer. -1 indicates the function cannot find the variable name. Any other value is the internal index of the variable.

 

Example

var nVariableIndex = GetVariableIndex (“Varname[subelement]”)

 

 

function GetNumVariables()

 

This function returns the number of variables you have in your model.

 

Return value

This function returns an integer that is the number of variables in the model.

 

Example

var nNumVariables = GetNumVariables()

 

 

function GetVariableName(nIndex)

 

This function returns the variable name associated with an ID number.

 

Return value

This variable returns a string that is the variable name at the index specified.

 

Example

var strVariableName = GetVariableName(10)

 

 

 

 

 

 

 

 

function GetVariableType(nIndex)

 

Each variable has a type. This function returns the type number for each variable. Values are as follows.

 

5 = Data

8 = Level

15 = Time base

17 = Auxiliary

19 = Game variable

22 = Initial

23 = Constant

24 = Unchangable constant

26 = Lookup table

27 = String variable

 

Return value

This function returns an integer that matches one of the values specified above.

 

Example

var nTimeIndex = GetVariableIndex (“time”)

var nVarType = GetVariableType(nTimeIndex)

 

 

function InitializeModel()

 

This function resets the model and marks it ready for another simulation.

 

Return value

The return value is an integer, 1 indicates the function has succeeded, 0 indicates an error.

 

Example

var nResult = InitializeModel()

 

 

function RunSim()

 

This function runs the simulation.

 

Return value

The return value is an integer, 1 indicates the function has succeeded, 0 indicates an error.

 

Example

var nResultModelOK = InitializeModel()

var nResultModelComplete = RunSim()

 

 

function GetSeriesNumVals(strVarName)

 

When a simulation is complete, this function returns the number of values stored in the time series for a specific variable.

 

Return value

This function returns an integer that is the number of values in the time series for this variable.

 

Example

var nNumVals = GetSeriesNumVals("time")

 

 

 

function GetSeries(strVarName)

 

This function returns an array of values for a specific variable.

 

Return value

This returns an array of doubles containing the time series.

 

Example

var nNumVals = GetSeriesNumVals("time")

var fVals = GetSeries("time")

 

 

function GetValueAtTime(strVarName, fTime)

 

This function returns the value of a parameter calculated at a specific time.

 

Return value

This returns a double containing the value.

 

Example

var fVal = GetValueAtTime("time", 0.0)