Lua Tutorial 1 -- May 30th, 2024

variables and "if, then" statements
mail@pastecode.io avatar
unknown
lua
16 days ago
1.7 kB
3
Indexable
Never
print ("Hello, World!") -- a basic print function

wait(1)
print("Hello, World!") -- a print function with a wait statement

local object -- a local object
object -- a global object

local object = 1 -- a local object with a value 
object = 1 -- a global object with a value

if object == 1 then
  print("Hello, World!") -- a print function parented to an "if, then" statement
end

if object ~= 1 then
  print("Error") -- an error print statement parented to an "if, then" statement
end

-- a better more efficient way to print an error is to use a warn statement

if object ~= 1 then
  warn("Error") -- this warn function will be highlighted in the output instead of just a regular print
end

-- next we will discuss a more efficient way to use a "wait" statement

task.wait(1)
print("Hello, World!") -- "task.wait(#)" is more efficient and precise when creating important scripts

task.wait(1)
if object == 1 then
  print("Hello, World!") -- in this code, we attatch the "if, then" statement to the "task.wait(#)" statement
end

-- now we will discuss "if, then" statements with "else" included

-- instead of using:

if object ~= 1 then
end

-- we can use:

if object == 1 then
  print("Hello, World!") -- this if then statement has two respective variables: an "if, then", and an "else" function
else 
  warn("Error")
end

-- now i will talk about "if, then" and "elseif, then" statements

local testVariable1 = 1 -- notice how "variable" is upper case but "test" is not.
local testVariable2 = 2

if testVariable1 == 1 then 
  print("1")
elseif testvarible2 == 2 then -- this function includes a complete professional type of "if, then" statement
  print("2")
else
  warn("Error")
end 
Leave a Comment