Operations & conditions
Operations & conditions can be performed on variables, depending on their type and values
Basic math operations
Neurox has 4 built-in functions for the 4 basic math operations :
SUM
SUB (subtract)
MPY (multiply)
DIV (divide)
Example :
DEFINE NEUROX
SUM(5,5) // 5 + 5
SUB(5,1) // 5 - 1
MPY(6,7) // 6 * 7
DIV(15,3) // 15 / 3
>>> 10
>>> 4
>>> 42
>>> 5They automatically print the result in the console if written like this.
You can also perform math operations with variables.
DEFINE NEUROX
SET a = 5
SET b = 5
SUM(a,b)
>>> 10It is possible to store the result of an operation in a variable, but it won't be printed in the console.
DEFINE NEUROX
SET a = 5
SET b = 5
SET result = SUM(a,b)Operation between integers and floats
As they have different type, they can still be used together for math operations. It will automatically converts the result to a float. This is a LuaU feature.
DEFINE NEUROX
SUM(5,0.5)
>>> 5.5Concatenate two strings
You can concatenate (assemble) two strings together with the SUM function.
DEFINE NEUROX
SUM("hello","world")
>>> "hello world"It works with variables as well. You can store the result in a variable too.
DEFINE NEUROX
SET a = "hello"
SET b = "world"
SUM(a,b)
>>> "hello world"Warning : you can't perform SUB, MPY and DIV on strings.
Conditions and boolean operations
Simple condition with IF
A condition always start with IF followed by a condition. If the condition is true, the content of the condition block will be executed.
DEFINE NEUROX
SET v1 = 1
SET v2 = 5
SET v3 = "None"
IF v2 > v1 THEN
SET v3 = "v2 is greater than v1"
ENDA condition always ends with END . If the condition is not true, nothing will happen.
Condition with ELSE and ELSEIF
If the condition is not true, you can set an ELSE statement.
DEFINE NEUROX
SET v1 = 0
SET v2 = 10
SET v3 = "None"
IF v1 < v2 THEN
SET v3 = "v1 is greater than v2"
ELSE
SET v3 = "v1 is less than v2"
ENDIn this case, the v3 value will be set to "v1 is less than v2"
If you desire to add another condition, use the ELSEIF statement
DEFINE NEUROX
SET v1 = 10
SET v2 = 10
SET v3 = "None"
IF v1 < v2 THEN
SET v3 = "v1 is greater than v2"
ELSEIF v1 == v3 THEN
SET v3 = "v1 and v2 are equal"
ELSE
SET v3 = "v1 is less than v2"
ENDComparison operators
You can use the following operators in conditions with Neurox :
<less than>greater than==equality!=inequality<=less or equal>=greater or equal
These operators always result in false or true.
= and == are totally different. One equal symbol is used to set values to variables and double equal is used as an operator.
Logical Operators
In Neurox, logical operators are and, or and not. They work exactly like LuaU operators :
The negation operator not always returns false or true. The conjunction operator and returns its first argument if this value is false or nil; otherwise, and returns its second argument. The disjunction operator or returns its first argument if this value is different from nil and false; otherwise, or returns its second argument. Both and and or use short-circuit evaluation; that is, the second operand is evaluated only if necessary. Here are some examples:
10 or 20 --> 10 10 or error() --> 10 nil or "a" --> "a" nil and 10 --> nil false and error() --> false false and nil --> false false or nil --> nil 10 and 20 --> 20
Last updated