How do I program in Roblox (Cont.)?
5.1 Condition (==, <, >)
We will pause our RPG game here.
First, disable the script you have been using:
Then create a new script under ServerScriptService, name it “main2“:
Inside main2, create a variable to describe your age:
Now we want to check if your age equals to 8.
We can use the comparison operator (==) to compare between numbers:
Now click “Run” to see the result:
true means Yes, so yes your age is 8!
What if you want to check if your age is 18?
(change 8 -> 18 at line 3)
Run it and you will see false, because your age is 8!
So when we use the comparison operators == , < , > (we will explain what < and > are very soon):
- There must be something to compare between LEFT and RIGHT
- A boolean will be the result of the comparison (either true or false)
Challenge 8:
Imagine you have a friend named Rei who is 10 years old:
- Create a varaible for Rei, name it reiAge and set his age to 10
- Using print() and == operator, and check if he is 10 years old
- Again using print() and == operator, check if he is 53 years old
- Using print() and == operator, check if your age is equal to Rei’s age
…Answer below…
…
…
…
Here is the answer of Challenge 8: