Operators
Operators are needed to perform calculations and comparisons. We can distinguish between four basic types in RealFlow. Without operators it wouldn’t be possible to make additions or multiplications, or compare different velocities, for example. The standard operators are:
Addition | 15 + 17 = 32 |
---|---|
Subtraction | 64 - 30 = 34 |
Multiplication | 10 * 12 = 120 |
Division | 80 / 10 = 8 |
Exponentiation | 12 ** 2 = 144 |
Modulus | 28 % 7 = 0 |
String concatenation | “John” + “Doe” = JohnDoe |
String repetition | “Hi” * 3 = HiHiHi |
The next group of operators is used for comparisons:
Less than | < |
---|---|
Greater than | > |
Less than or equal | <= |
Greater than or equal | >= |
Equal | == |
Not equal | != |
==
”. The single “=
” is just used for assignment, e.g. in variable names, as shown many times before.
A third group is called Boolean operators:
and | or | not |
They are mostly used to perform multiple comparisons, e.g.:
if (mass >= 100 and friction == 0.001): do something if (velocity >= 5.0 or velocity <= 10.0): do something
The last class are augmented operators. This is a very special class and mostly used for cases where you have to sum up values. There are instructions like this one:
while (particles): particle_mass = particles.getMass() total_mass = total_mass + particle_mass
In this example, the script loops through all particles and sums up their individual masses to get a total mass value. With an augmented operator this could also be written as:
while (particles): particle_mass = particles.getMass() total_mass += particle_mass
The most common augmented operators are:
+= | -= | /= | *= | **= | %= |
Python offers a few more operator types, but they are not often used with RealFlow scripts. As you can see, operators work exactly as you know from school. They resemble basic operations, and you will definitely need to use them frequently. You also might have noticed that operators do not contain mathematical functions, such as sine, square root or tangent. These functions are part of another class and treated separately.