Easy Written By Halru

Useful operators Created on: 01-01-2019

Operators that you will use frequently!

Operators

Operators are symbols that conduct operations. This may include arithmetic, relational, or logical operations. Arithmetic operators would be calculations such as addition, subtraction, multiplication or division.

  • They are useful when you need to conduct basic calculations in a game (e.g. Adding XP!)

Logical operators would be statements that indicate if a statement is true or false.

  • They are useful when you need to check certain conditions (e.g. Is the player stunned?)

Relational operators would be comparing two variables and return a true or false boolean.

  • They are useful when you need to check conditions (e.g. Does the player have enough money to buy this item?)

Arithmetic Operators

-- Operator: Addition (+)
local x = 3 + 2 -- Hence, x = 5.

-- Operator: Subtraction (-)
local x = 3 - 2 -- Hence, x = 1.

-- Operator: Multiplication (*): This is the asterik on your keyboard, usually found at (8) on your keyboard.
local x = 3 * 2 -- Hence, x = 6

-- Operator: Division (/): This is the dash on your keyboard, the same key you use to type (?).
local x = 3 / 2 -- Hence, x = 1.5

-- Operator: Exponentials (^): This is a small triangle that can be found on (6) on your keyboard.
local x = 3 ^ 2 -- Hence, x = 9 as (3 x 3 = 9). This means the same as 3 to the power of 2.

-- Operator: Modulus (%): This is the percentage found on (5), and calculates the remainder of a value.
local x = 3 % 2 -- As 3 can only be divided by 2 once, the remainder would be 1. This would return the value 1.

Relational Operators

-- Operator: Equal to (==): This checks if one value is the same as another value. 
if x == 3 then -- This will run if x is indeed equal to 3.

-- Operator: Not equal to (~=): The curly can be found at the left side of 1, usually.
if x ~= 3 then -- This will run when x is any number but 3.

-- Operator: Greater than (>): 
if x > 3 then -- This will run when x is any number greater than 3.

-- Operator: Smaller than (<):
if x < 3 then -- This will run when x is any number smaller than 3.

-- Operator: Greater than or equal to (>=):
if x >= 3 then -- This will run when x is greater than 3 or if it is indeed 3. 

-- Operator: Less than or equal to (<=):
if x <= 3 then -- This will run when x is smaller than 3 or if it is indeed 3. 

Logical Operators

-- Operator: And (and): This will return a value of 'true' when both conditions are true.
if (x == 3 and y > 4) then -- This will only run if x is 3 and y is any number bigger than 4. If x is 2 but y is any number bigger than 4, it will not run.

-- Operator: Or (or): This will return a value of 'true' when either conditions are true.
if (x == 3 or y > 4) then -- This will run when x is 3 or y is any number bigger than 4. If x is 2 but y is a number bigger than 4, this will still run.

-- Operator: Not (not): This will return a value of 'true' when the condition is false.
if not (x == 3) then -- This will run when x is any number but three. If x is three, this will return as 'false'.

Easy Written By Halru

See Halru's profile on Roblox

Discussion