Lesson 1: Introduction to Luau
Goal: read and write the Luau you need for scripts. This lesson uses only the language, not SwizzinIRC.
local function double(n: number): number return n * 2end
print(double(21)) -- 42
local words = { "classic", "irc" }for i, w in words do print(i, w) -- 1 classic, then 2 ircend
local greeting = `Hello, {words[1]}!` -- string interpolation with backticksprint(greeting)What it does
Section titled “What it does”double is a function that returns a value. The for loop walks a table. Backtick strings insert values with { }. Inside SwizzScript, print writes to the Script Console, the same as swizzin.log.
What is available
Section titled “What is available”The sandbox provides coroutine, table, string, utf8, math, bit32, os (time and date only), buffer and vector. It removes require, load, dofile, io, debug, package and similar. See Luau fundamentals.
Expected result
Section titled “Expected result”Running this as a script shows 42, the two list lines and the greeting in the Console tab of the Script Manager.
Common mistakes
Section titled “Common mistakes”- Forgetting
local, which makes a global. - Tables start at index
1, not0. - Not-equal is
~=, not!=. - Trying to
requireanother file: scripts cannot load other scripts.
Troubleshooting
Section titled “Troubleshooting”attempt to call a nil value: a name is misspelled, or the function is defined later in the file.- Nothing appears: the script is Off. Turn it on in the Script Manager. See Script errors.