Paste Markdown¶
For loop¶
local myNum = 0
for i = 1, 10, 1 do
myNum = myNum + 1
print(myNum)
end
While loop¶
local myNum = 0
local myBool = true
while myBool == true do
myNum = myNum + 1
print(myNum)
if myNum == 10 then
myBool = false
end
end
print("The while loop has ended", myBool)
print("The final value of myNum is", myNum)
Table Example¶
-- An empty table
local myTable = {}
-- Add an item to the table
myTable[1] = "banana"
table.insert(myTable, "orange")
print(table)
for i=1, #myTable do
print(myTable[i])
end
local boxTable = workspace.boxModel:GetChildren()
print(boxTable)
boxTable[4].BrickColor = BrickColor.new("Really red")
All Steps Example¶
local allSteps = workspace.magicStepsModel.stepModel:GetChildren()
while wait(1) do
local randNum = math.random(1, #allSteps)
local randStep = allSteps[randNum]
for i=0, 1, .2 do
task.wait(.1)
randStep.Transparency = i
end
randStep.CanCollide = false
wait(.5)
for i=1, 0, -0.2 do
wait(.1)
randStep.Transparency = i
end
randStep.CanCollide = true
end