Loops in Lua; Using Instancing to Create 3D Objects in Roblox

MDN
8 min readDec 14, 2020
what happened?!?

Lua

Lua (/ˈluːə/ LOO-ə; from Portuguese: lua [ˈlu.(w)ɐ] meaning moon)[a] is a lightweight, high-level, multi-paradigm programming language designed primarily for embedded use in applications.

Lua is used as the scripting language for a variety of applications, including Roblox, Sonic-Pi, Pico-8, and Norns. In other words, it is a an ideal creative coding language to learn as a software engineer using high level tools.

Loops

Today we’re going to talk about loops in Lua. A loop is a block of code which repeats until a desired condition is met. Let’s look at how a for loop is implemented.

//Luafor i=0,5 do print(i) end// 1
// 2
// 3
// 4
// 5

for is a reserved word in Lua which tells the compiler that either a numeric or generic loop is to follow. In this case we have numeric loop which is printing a number.

i=0 is our variable declaration. It states that the variable i is a number (data types in Lua can be numbers, boolean, objects, or string), and that its initial value is 0.

,5 is the setting of the condition for the loop. It creates the end condition for the loop; when i is equal to the value 5 the loop…

--

--