So today I got a crash course in if statements, which are used to determine something about the situation before performing an action.
If statements always follow this formula, at least in some form -
if guard (a condition or set of conditions that must be true) then
body (what to do if condition is true)
end
You can also use logical operators - such as and, or, not, else, and elseif. It’s a good idea if you are using multiple determinations to use parenthesis around each condition to avoid confusion.
For example, let’s pretend I am making a racing game. If it’s myself or my friend Cuppycake, I want a special car - but everyone else can make a plain car and play too.
In plain English:
If the person that clicked this is Amethyst, spawn a purple car.
Otherwise If the person that clicked this is Cuppycake, spawn a pink car.
Otherwise, spawn a white car.
In Lua / Metascript (Let’s just assume username is being passed to these statements correctly - I’ll leave the assignment out.)I would put this into my trigger: (no guarantees that this works, I am doing it off the top of my head!)
if username == “Amethyst” then
CreateObject(“PurpleCar”, 5, 5, 0, 0)
—creates an object from the PurpleCar template, at x,y,z coordinates 5,5,0 with 0 rotation)
elseif username == “Cuppycake” then
CreateObject(“PinkCar”, 5, 5, 0, 0)
else
CreateObject(“WhiteCar”, 5, 5, 0, 0)
end
Neat! We also went over the different relational operators -
I think that about covers it… I am off to try this stuff out now! Wish me luck!