Skip to content

OSL ‐ Operators and Expressions

Mistium edited this page Jan 23, 2024 · 18 revisions

Mathematical Equations in OSL

In originOS scripting, mathematical equations play a crucial role in creating dynamic systems and performing calculations. These equations involve operators and comparisons that allow you to manipulate data and make decisions based on conditions. Here's a comprehensive guide to mathematical equations in OSL:

How They Function

Mathematical expressions are evaluated based on the given operators and data. For example:

if true and false (

When parsed, it becomes:

if false (

The and statement replaces true and false with false, demonstrating how expressions can be dynamically altered.

Syntax

The general syntax for mathematical equations in OSL is:

data (operator) data2

Operators

1. +

  • (If both data are integers) Adds the number on the right and left together.
  • (If either data is not an integer) Joins the right and left with a space in-between.
  • (If data on the left is an array) Appends data on the right to the array.

Example:

result = 5 + 3    // result is 8
text_result = "hello" + "world"    // text_result is "hello world"
array_result = ["apple"] + ["orange"]    // array_result is ["apple", "orange"]

2. ++

  • (If both data are arrays) Concatenates the two arrays together.
  • (Else) Joins the two sides together with no spaces.

Example:

array_result = ["hello"] ++ ["world"]    // array_result is ["hello", "world"]
text_result = "hello" ++ "world"    // text_result is "helloworld"

3. -

  • Takes the number on the right away from the number on the left.

Example:

result = 8 - 3    // result is 5

4. /

  • Divides the number on the left by the number on the right.

Example:

result = 10 / 2    // result is 5

5. *

  • (If the data on the left is a number) Multiplies the number on the left and right together.
  • (If the data on the left is text) Repeats the text by the number on the right.

Example:

result = 5 * 3    // result is 15
text_result = "hello" * 3    // text_result is "hellohellohello"

6. %

  • Runs modulus on the left number using the right number.

Example:

result = 10 % 3    // result is 1

7. ^

  • Runs an exponential on the left number.

Example:

result = 2 ^ 3    // result is 8

Comparisons

1. ==

  • True if both sides are the same (not case sensitive).

Example:

if "apple" == "Apple" (
   // This block will be executed because the comparison is not case-sensitive.
)

2. !=

  • True if both sides aren't the same (not case sensitive).

Example:

if "apple" != "orange" (
   // This block will be executed because the strings are not the same.
)

3. ===

  • True if both sides are the same (case-sensitive).

Example:

if "apple" === "apple" (
   // This block will be executed because the strings are the same in a case-sensitive manner.
)

4. >

  • True if the number on the left is bigger than the one on the right.

Example:

if 10 > 5 (
   // This block will be executed because 10 is greater than 5.
)

5. <

  • True if the number on the right is bigger than the one on the left.

Example:

if 5 < 10 (
   // This block will be executed because 10 is greater than 5.
)

6. >=

  • True if the number on the left is bigger than or equal to the one on the right.

Example:

if 10 >= 10 (
   // This block will be executed because 10 is equal to 10.
)

7. <=

  • True if the number on the right is bigger than or equal to the one on the left.

Example:

if 10 <= 20 (
   // This block will be executed because 20 is greater than or equal to 10.
)

Boolean Expressions

1. and

  • True Examples: true and true.
  • False Examples: false and true, true and false, false and false.

Example:

if true and ( 3 > 2 ) (
   // This block will be executed because both conditions are true.
)

2. or

  • True Examples: true or true, false or true, true or false.
  • False Examples: false or false.

Example:

if false or ( 5 == 5 ) (
   // This block will be executed because at least one condition is true.
)

3. xor

  • True Examples: true xor false, false xor true.
  • False Examples: true xor true, false xor false.

Example:

if true xor ( 5 < 3 ) (
   // This block will be executed because one condition is true and the other is false.
)

4. nor

  • True Examples: false and false.
  • False Examples: false and true, true and false, true and true.

Example:

if false nor ( 2 != 2 ) (
   // This block will be executed because both conditions are false.
)

These mathematical equations and boolean expressions provide a powerful toolkit for creating dynamic and responsive behavior in originOS applications. Choose the appropriate operators and comparisons based on your specific needs and desired outcomes.

originOS Wiki

Wiki Views:
:views

OSL | RSH | ICN

Clone this wiki locally