SimTalk Reference

The programming language SimTalk extends the ways you can model and control your simulation. Each object has built-in properties providing many useful features. When your model requires more detailed or completely different properties, you will program these in the programming language SimTalk.

First, you will enter the statements, which the built-in Interpreter program executes, into the object Method . You can also combine the Method object with the material flow objects and the information flow objects to create models of great complexity. Then press the F7 and F5 keys to execute your source code.

When you then run the simulation, the Interpreter executes the source code, which you entered into your Method line-by-line and takes the actions you programmed.

Note:

SimTalk normally does not distinguish between upper- and lower-casing for the names of methods and attributes which you enter into the source code of your Method objects.

SimTalk 2.0 makes programming methods in Plant Simulation faster, easier, and less error-prone. You can change between SimTalk 1.0 and SimTalk 2.0 by clicking New Syntax on the Tools ribbon tab of the Method you are programming. If you want to use SimTalk 2.0 syntax for all new Methods which you are going to program, activate New Syntax in the Method class in the Class Library. Changes caused by SimTalk 2.0 also affect how the dialog Show Attributes and Methods displays the signature of attributes and methods.

Note:

You can select if you want to use theSimTalk 2.0 notation or the SimTalk 1.0 notation for each and every of your Methods. You can also freely mix SimTalk 2.0 notation and SimTalk 1.0 notation in your simulation models. There is no need to reprogram your existing source code.

Note:

Clicking in an existing Method which you programmed in SimTalk 1.0 notation automatically converts the source code to the correct SimTalk 2.0 notation.

Note:

To convert the source code of all existing Methods in a simulation model to the new syntax, hold down the Shift key, click on the object Basis in the Class Library with the right mouse button and click Convert all Methods to New Syntax.

SimTalk 2.0 encompasses:

  • A line-controlled syntax: You no longer need to type a semicolon (;) at the end of each statement. Instead, you can simply enter a single statement into a line. As you still might want to be able to split a statement and distribute it over several lines, the interpreter automatically determines if the statement is still incomplete and, if this is the case, continues it in the next line. In addition, you can enter a semicolon after a statement to add another statement to the same line.

    SimTalk 2.0

    SimTalk 1.0

    MyStation.setName("MyStation")

    MyStation.setName("MyStation");

  • A simplified body syntax: In SimTalk 1.0 the source code requires the keywords is do end. SimTalk 2.0 does not need these keywords. In SimTalk 2.0 you will declare parameters using the keyword param, local variables using the keyword var, and the return value using the keyword -> (hyphen plus right angle bracket).

    SimTalk 2.0

    SimTalk 1.0

    MyStation.setName("MyStation")
    is
    do
       MyStation.setName("MyStation");
    end 

  • Improved referencing of methods and global variables: In SimTalk 1.0 Methods and Variables are referenced with the reference operator. In SimTalk 2.0 you reference Methods and Variables with a leading & operator, for example var o:object := &Method.

  • New div/mod operator: In SimTalk 1.0 the // operator represents an integer division and the \\ operator represents an integer modulo operation. In SimTalk 2.0 the keyword div represents an integer division and the keyword mod represents an integer modulo operation.

  • Improved string literals: In SimTalk 2.0 a backslash (\) inside of a string literal will only protect double quotes and line breaks. The backslash will not protect another backslash any longer as in SimTalk 1.0.

  • You can enter time literals into your source code. A time literal starts with a digit and must contain one or more colons. A time literal can contain a decimal point and decimal places.

    wait 1:30  -- wait for 1 minute and 30 seconds
    &Methode.methCall(1:0:0:0.5) -- call the method in 1 day and half a second
  • Default arguments: You can define default arguments for formal parameters by entering an assignment operator and the default value after the parameter declaration, for example: param x := 0.

  • Simplified control flow statements: The control structures which you can insert with the command Insert Control Structure into your source code, reflect this. You can now enter control flow statements using the simplified syntax:

  • if-end instead of if-then-end

  • for-next instead of for-loop-next

  • switch-case-end instead of inspect-when-then-end

  • while-end instead of while-loop-end

  • The keyword then in if-statements is optionally allowed.

  • The keyword loop in loops is optionally allowed.

  • We added the keyword continue, which skips the rest of the loop iteration and continues with the next iteration. If the iteration was the last iteration, continue exits the loop.

  • A changed about equal operator. You now have to use:

  • ~= instead of ==, compare Tolerance for about equal (~=) comparison.

  • <~= instead of <==

  • >~= instead of >==

  • New operators for adding, subtracting, or multiplying a value:

  • x += y is short for x := x + y

  • x -= y is short for x := x - y

  • x *= y is short for x := x * y

  • An improved list and table syntax: You now only enter list ranges using curly brackets {}. The optional 1.0 syntax using a grave accent `[] is no longer available.

You can read out an element of a one-dimensional list with the bracket operator []. This works for Stacks and Queues as well. You can read and remove an element from a DataList with the new built-in method remove.

Note:

When reading the contents of a cell of a DataList with the bracket operator [ ] in SimTalk 1.0, the contents of the designated cell was read and removed. The remaining cells moved up by one position.

When assigning a value to the designated cell with the bracket operator to a DataList in SimTalk 1.0, this value was inserted into the cell and the existing cells moved down by one position.

Note:

When reading the contents of a cell with the bracket operator in SimTalk 2.0, the contents of the designated cell will be read, but will remain in the DataStack, DataQueue, and the DataList.

When assigning a value to the designated cell with the bracket operator to a DataList in SimTalk 2.0, this value will just overwrite the contents of the existing cell. This way a DataList will behave the same way as a DataTable with one column.