Now it is necessary to make the system add some constant (e.g. 3) to the temperature value every second.
- If the temperature value is less than
the maximum temperature (e.g. 100), then add a constant into the Value
property of the "Temperature" variable.
- If the temperature value is greater than
(or equals to) the maximum temperature, then set a minimum temperature value into the Value
property of the "Temperature" variable (e.g. 0).
- Repeat cycle.
Therefore it is necessary to execute the following steps in the onTick
1. Creating of variables
In the onTick
event, in the area in the right part of the "Events
" tab enter the 1st line of script:
By this script, you have just created a variable oTemper
, that will be represented by the "Temperature"
The variable name in the script mustn't imply spaces, diacritic and special characters. It is a good practice to have the first letter of the variable name in lower case that perceives type of the variable, e.g.
n = number
b = boolean
s = string (text)
o = object - oTemper in our case, etc.
a = array of values, etc.
Notice that the variable has no defined data type. Each variable is so-called Variant
, meaning a variable holds inside not only the value but also the data type. After being created, the variable is empty (undefined
data type). Only after the value is assigned (this process will be described in a while) the variable finds out what is being assigned to it and then sets its data type accordingly.
2. "Temperature" object Assignment
Now write the 2nd line of the script:
oTemper = pMe.Pm("../Data/#vars/Temperature");
A value is assigned into the oTemper
variable that is now of the Object
: These two rows can be shortened into a single row: var oTemper = pMe.Pm("../Data/#vars/Temperature");
Note for VBScript
: Statement Set
before assigned variable must be used only if an object
Each event of any object in the PROMOTIC system has a pMe
parameter (variable). This parameter is of the Object
data type and is set by the PROMOTIC system to be the object where the corresponding event occured.
In case of the onTick event in the Emul object the pMe parameter points to the Emul object.
Each object has the Pm method. This method has a single parameter that is a text (String), that represents the path in the tree of Pma objects to the desired Pma object (the text is inside quotation marks making the script aware that it is a value of the String type).
Two types of addressing can be used in the PROMOTIC system (i.e. definition of path to object):
addresssing – starts always from the PmaRoot
object, syntax starts with slash. (for example "/BoilerPlant/Boiler1/Data/#vars/Temperature"
addressing - starts always from the object where the Pm
method is called. (for example "../Data/#vars/Temperature"
The main disadvantage of the absolute addressing is the fact that once the structure in the tree of Pma
objects is modified the object may become invalid. For example, you can copy the "Boiler1" object in order to create a new object "Boiler2" (do not do this in the application now). There would be exactly the same objects present in the "Boiler2" as in "Boiler1" (including the corresponding settings). If the absolute addressing would have been used, the script in "Boiler2" would work with values from "Boiler1". Usage of relative addressing would avoid this problem.
: Instead of writing the scripts manualy, you can use the script wizard that can make script writing a lot easier.
The script wizard can be activated clicking by the right mouse button on the script editing area. In the displayed local menu select "Script wizard ..." item and then select "Pma object - reference" in order to create an object reference.
In the displayed window in the "Variable" configurator enter the variable name that is to be linked with object reference (oTemper).
In the "Value" configurator, select (use the button with three dots) the desired object (Temperature variable in the PmaData object) and check the "Relative path" configurator.
The wizard can also help you create a new variable, but we are not going to use this function now - the variable has been created in previous steps.
3. Check and set value of "Temperature" object
Write this script on the following line:
if (oTemper.Value >= 100)
oTemper.Value = 0;
oTemper.Value += 3; //+= is the shortened entry version oTemper.Value = oTemper.Value + 3;
This part of the script uses the statement if
. This statement allows to define a group of statements to be executed if the condition is met (temperature value is greater than 100°C) and other group of statements if the condition is not met (temperature value is less than 100°C).
The approach to the object property that was theoretically explained formerly, is used here practically for the first time – i.e. the way for setting the object property when Object.PropertyName
There is both reading and writing the value into the Value property here.
The "Temperature" object (of the PmVar type) holds more properties (e.g. property Note, Unit, etc.), but the most important is the Value property. This property returns the value of the temperature (of the Single type – thus you've set it in the "Temperature" object).
You've finished your first script in the PROMOTIC system. You should have the following text in the right part of the tab in the "Temperature"
object on the "Events
" tab while selected the onTick
var oTemper = pMe.Pm("../Data/#vars/Temperature");
if (oTemper.Value >= 100)
oTemper.Value = 0;
oTemper.Value += 3;
Confirm all changes by pressing the button
Now you can start the application.