I've found it impossible to use the debugger to debug expressions and variables when using SimTalk 1.0 in Plant Simulation 12.1. Please step through the attached model and look at the variables and expressions tab of the debugger. When trying to add i and j as debug expressions Plant Simulation returns "Cannot evaluate expression" as error. Tooltips are also not working when holding the cursor over the variables in the code. And for and local are added as variables instead of i and j in the Variables list.
When using SimTalk 2.0, this is not an issue. Assuming that the method is programmed exactly to 2.0 specification. Trying to use a hybrid format (local instead of var for example, which is acceptable format) results in the same errors.
Solved! Go to Solution.
thanks for reporting this issue.
This will be fixed in the next maintenance pack for version 12.1 (12.1.1).
Thank you Ralf!
Another question relating to SimTalk 2.0 is the use of the & operator. Previously it was possible to execute a method referenced by a variable like this:
result := (VariableReferencingAMethod)(ParametersToMethod);
To use the same thing in SimTalk 2.0, I've been forced to do this.
result := &VariableRefrencingAMethod.execute(ParametersToMethod)
Is it the correct way to do it now? I found a lack of help content for the & operator.
Pardon me for the intrusion, what are simtalk 1.0 and 2.0. Is 2.0 a new version of simtalk in Plant Simulation 12? Where can I find further information about?
The correct way to do it:
var obj: object := &MyMethod result := obj.execute(ParametersToMethod) var obj2: object := &MyVariable result := obj2.value
Note that obj.execute works exactly like in SimTalk 1.0. This was actually the official way to call the Method referenced by a Variable or a local variable in SimTalk 1.0 too. The parentheses were the old way to do this.
SimTalk 2.0 is the new and improved syntax introduced with Plant Simulation 12.1. The old syntax is called SimTalk 1.0, and of course it still works in Plant Simulation 12.1 and future versions. The Method object now has the built-in attribute 'UsingOldSyntax' that sets if the Method uses old or new syntax.
The main goal for SimTalk 2.0 was to make programming easier, for example by getting rid of the semicolons.
A small example that shows some of the differences:
-- SimTalk 1.0 is do local x : integer; if Variable < 100 then x := 42; end; end; -- SimTalk 2.0 var x : integer if Variable < 100 x := 42 end
So directly accessing it and running the method is not possible? I need to set it to a variable first?
&MyVariable.execute(ParametersToMethod) doesn't seem to work either.
&MyVariable isn't analogous to call by reference like (MyVariable) as explained in the help text under Calling a Method? It's analogous to ref(MyMethod)? In SimTalk 1.0 ref(MyMethod).execute(ParametersToMethod) works though.
Also, shouldn't entering &MyVariable in the Expressions window show MyMethod instead of MyVariable?
Edit: Ok, I get it now. MyVariable.execute is how I should write it...
Of course you can directly access the Variable object.
With my example I wanted to point out, that & replaces the ref(), so you have to write & everywhere you would have written ref(), and only there. So you need to write
without the &, and
with the &.
You want to call 'execute' for the object MyVariable references, not for MyVariable itself (which does not understand 'execute').
The same goes for 'MyVariable.value'. If MyVariable points to a Variable, for example to 'Variable42', MyVariable.value would return the value of 'Variable42'. On the other hand '&MyVariable.value' would return the value of MyVariable, which is the object 'Variable42', and not its value.
(Note: You would not ever want to write '&MyVariable.value', because this would be the same as 'MyVariable', which is much simpler.)