Variables - general information
This page has been automatically translated and has not been reviewed in detail yet. Therefore, the translation might not be completely accurate.
NeuroomNet supports the following data types
Icon | Name | Description | Examples of values |
---|---|---|---|
bool | Boolean values (truth value) can only assume two states. | true/false | |
Number | Integer values | 0 / 1 / 42 | |
Float | Floating point number | 3.14 / 0.5 | |
Text | Strings | Hello / 0xff5a11 | |
Time | Formatted time | 08:15 / 8:15am | |
DateTime | Formatted date and time | 02/15/2023/08:15 |
In addition, each data type is available as a list. The icon has three small dots on the left:
As the name suggests, lists contain several Bool, Number, Float etc. values.
Basic ideas of data types
Text: 1 + 2 = 12
Number: 1 + 2 = 3
From this example it is easy to see that it makes a big difference whether processing software interprets corresponding input as a number or text.
Traditionally, most high-level languages use data types for variables. Some languages also forego the concept because it is sometimes more convenient. However, this usually has to be paid for with more effort in finding runtime errors.
In NeuroomNet we have also decided on data types, since NeuroomNet mainly communicates with devices from many manufacturers and these usually already define data types in their protocols. So if you receive a code in the form of "0123" from a device, you can rely on it being kept that way because you have defined - here comes a text. In an automatic conversion, this text would probably be interpreted as a number and converted to '123'.
Of course, in NeuroomNet you can also explicitly convert one data type to the other if you want.
Type conversion
You can convert one data type to another. In high-level languages, this process is also called typecasting. However, a conversion must be technically possible. The following examples are intended to illustrate which conversions work and which do not.
Note: Almost anything can be converted into text, which is why this direction is not specifically listed here.
Examples for converting a text variable ("Original Text") to Number, Float, Bool:
Original Text | Convert to Number | Convert to Float | Convert to Bool |
---|---|---|---|
"Hello" | Error | Error | true |
"0" | 0 | 0.0 | false |
"1" | 1 | 1.0 | true |
"3.14" | 3 | 3.14 | true |
"1234" | 1234 | 1234.0 | true |
"12 34" | Error | Error | true |
"" | 0 | 0.0 | false |
Visibility of variables
The user mainly encounters the visibility of variables in the script blocks. Visible means from where can I access these variables. We differentiate between 'global' and 'block' variables. Variables created with the 'Global' attribute can be accessed from anywhere, for example from a dashboard or all scripts etc.
Variables with the 'Block' attribute can only be used by events or actions in the script block in which they were created.
Icon for global variables
Icon for block variables
Why global and block variables?
Actually, variables that can be accessed from anywhere would be sufficient for all use cases. So far, so true, but impractical. The number of global variables can then quickly skyrocket and become confusing.
It is often the case that you write the parameter of an event into a variable, only to test in the same block with an IF condition whether a certain value is in the variable. Since the names of global variables must be unique, you would have to come up with a new unique name for each block and the list of variables would quickly become very long. If a variable is only visible in the block, you can always use the same variable names for blocks that do similar things and you don't run the risk of using the variable somewhere else and triggering any side effects. Therefore, entire blocks including variables can also be copied. Usually you only have to adjust a few constants or component names.