<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.figuramc.org/index.php?action=history&amp;feed=atom&amp;title=Lua_Basics</id>
	<title>Lua Basics - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.figuramc.org/index.php?action=history&amp;feed=atom&amp;title=Lua_Basics"/>
	<link rel="alternate" type="text/html" href="https://wiki.figuramc.org/index.php?title=Lua_Basics&amp;action=history"/>
	<updated>2026-06-12T06:19:15Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://wiki.figuramc.org/index.php?title=Lua_Basics&amp;diff=546&amp;oldid=prev</id>
		<title>Slyme: Remove that warning at the top.</title>
		<link rel="alternate" type="text/html" href="https://wiki.figuramc.org/index.php?title=Lua_Basics&amp;diff=546&amp;oldid=prev"/>
		<updated>2024-10-06T01:13:33Z</updated>

		<summary type="html">&lt;p&gt;Remove that warning at the top.&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 01:13, 6 October 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{Notice&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;/Warning&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{Notice&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt; &lt;/del&gt;|content=&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&#039;&#039;&#039;&#039;&#039;&#039;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| content = &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;I highly recommend reading the [https://www.lua.org/manual/5.2/ Lua Reference] and [https://www.lua.org/pil/contents.html Programming in Lua] if you have the time. I provide a basic rundown of the most used functionality for Figura, but not everything gets covered.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;}}&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;}}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;----&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;{{Notice&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt; |content=I highly recommend reading the [https://www.lua.org/manual/5.2/ Lua Reference] and [https://www.lua.org/pil/contents.html Programming in Lua] if you have the time. I provide a basic rundown of the most used functionality for Figura, but not everything gets covered.}}&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==How a computer reads code==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==How a computer reads code==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key wiki:diff:1.41:old-545:rev-546:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Slyme</name></author>
	</entry>
	<entry>
		<id>https://wiki.figuramc.org/index.php?title=Lua_Basics&amp;diff=545&amp;oldid=prev</id>
		<title>Slyme: Ported Katt&#039;s Lua Basics page to MediaWiki and made a few minor edits.</title>
		<link rel="alternate" type="text/html" href="https://wiki.figuramc.org/index.php?title=Lua_Basics&amp;diff=545&amp;oldid=prev"/>
		<updated>2024-10-06T01:13:05Z</updated>

		<summary type="html">&lt;p&gt;Ported Katt&amp;#039;s Lua Basics page to MediaWiki and made a few minor edits.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Notice/Warning&lt;br /&gt;
 |content=&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
}}&lt;br /&gt;
----&lt;br /&gt;
{{Notice&lt;br /&gt;
 |content=I highly recommend reading the [https://www.lua.org/manual/5.2/ Lua Reference] and [https://www.lua.org/pil/contents.html Programming in Lua] if you have the time. I provide a basic rundown of the most used functionality for Figura, but not everything gets covered.}}&lt;br /&gt;
&lt;br /&gt;
==How a computer reads code==&lt;br /&gt;
Code is basically just a list of instructions telling the computer step by step what to do. It is read line-by-line and the instructions are executed right away.&lt;br /&gt;
==Comments==&lt;br /&gt;
When there are 2 minus signs &amp;lt;code&amp;gt;--&amp;lt;/code&amp;gt;, everything after it is ignored by Lua. These are called comments. They have no effect on the code that is executed and can be safely removed. Their primary purpose is to add raw text that can be used to aid in the understanding of code.&lt;br /&gt;
&amp;lt;syntaxHighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Comments are not compiled and do not affect code&lt;br /&gt;
local a = 2 -- Everything up to the next newline will be ignored.&lt;br /&gt;
-- Can also be used to hide code from the compiler without actually removing it:&lt;br /&gt;
-- local b = 4&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
Another form of comment is &amp;lt;code&amp;gt;--[[  ]]&amp;lt;/code&amp;gt;. When this is used, everything between the square bracket pairs will be ignored. Newlines do not affect this. This type of comment is commonly referred to as a Long Comment.&lt;br /&gt;
&amp;lt;syntaxHighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local a = 2&lt;br /&gt;
--[[ comment comment&lt;br /&gt;
ignores newlines &lt;br /&gt;
ignores pretty much everything&lt;br /&gt;
]] local b=2 --long comments end strictly at the `]]`&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
==Variables==&lt;br /&gt;
Variables store values. Lua is a dynamically typed language, meaning any variable can store a value of any type. You can define a variable using the `local` keyword. Local variables are accessible below the line they were declared, but will not breach their scope.&lt;br /&gt;
&amp;lt;syntaxHighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local a&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
Most of the time, you will want to instantly assign a value to that variable. In lua, if you use `=` it will store the value on the right inside the variable on the left.&lt;br /&gt;
&amp;lt;syntaxHighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local a = 2 -- the variable named &amp;quot;a&amp;quot; now stores the value 2&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
After a variable has been declared, you can assign a new value to it by using &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt; again. Note that the &amp;lt;code&amp;gt;local&amp;lt;/code&amp;gt; keyword is only used when creating the variable for the first time.&lt;br /&gt;
&amp;lt;syntaxHighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local a = 2&lt;br /&gt;
a = 4 -- the variable &amp;quot;a&amp;quot; now stores 4&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
Multiple variables can be declared and assigned on one line.&lt;br /&gt;
&amp;lt;syntaxHighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local a, b = 1, 2&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
Variables are limited in what characters can be used as an identifier (variable name). Only letters, numbers, and `_` can be used in a valid identifier, and it cannot start with a number. None of Lua&amp;#039;s keywords (&amp;lt;code&amp;gt;and&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;or&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;while&amp;lt;/code&amp;gt;, etc.) can be used as a variable name.&lt;br /&gt;
&amp;lt;syntaxHighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local a123&lt;br /&gt;
local _b&lt;br /&gt;
local KEKW&lt;br /&gt;
local 123A -- invalid. Starts with a number.&lt;br /&gt;
local has-water -- invalid. Uses character `-`&lt;br /&gt;
local and -- invalid. `and` is a lua keyword.&lt;br /&gt;
local local -- invalid. `local` is a lua keyword.&lt;br /&gt;
local _ -- This name specifically is used to denote throwaway variables in loops.&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
If you assign a value to a value to a variable that has not been declared using &amp;lt;code&amp;gt;local&amp;lt;/code&amp;gt;, you will create a &amp;#039;&amp;#039;global&amp;#039;&amp;#039; variable. Global variables are accessible from the entire Lua environment. This may seem like a good thing to the inexperienced, but because they are accessible anywhere it is common for users to make mistakes when they reuse global variables for other purposes and accidentally overwrite it.&amp;lt;br&amp;gt;&lt;br /&gt;
There is almost never a good reason for using global variables, so always stick to &amp;lt;code&amp;gt;local&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;syntaxHighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- c was not declared local beforehand,&lt;br /&gt;
-- meaning there is now the value `10` at global variable `c`&lt;br /&gt;
c = 10&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
Variables can be used in place of values.&lt;br /&gt;
&amp;lt;syntaxHighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local a = 2&lt;br /&gt;
print(a) --&amp;gt; prints `2` to the chat&lt;br /&gt;
a = a + a&lt;br /&gt;
print(a) --&amp;gt; prints `4` to the chat&lt;br /&gt;
a = a + a&lt;br /&gt;
print(a) --&amp;gt; prints `8` to the chat&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
When you try to use a variable that hasnt been assigned a value, the value `nil` will be returned.&lt;br /&gt;
&amp;lt;syntaxHighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local a&lt;br /&gt;
print(a) --&amp;gt; nil&lt;br /&gt;
print(d) --&amp;gt; nil&lt;br /&gt;
&lt;br /&gt;
print(c) --&amp;gt; 10 (the global variable we declared earlier lol)&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Functions==&lt;br /&gt;
&lt;br /&gt;
A function contains code that can be executed by calling the function. This is useful if you want to use the same code multiple times and can make your code more structured.&lt;br /&gt;
&lt;br /&gt;
To define a function you use the &amp;lt;code&amp;gt;function&amp;lt;/code&amp;gt; keyword, then the name of the function and &amp;lt;code&amp;gt;()&amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
Any code after it will be considered inside this function, until you tell Lua that the function is done here by using the &amp;lt;code&amp;gt;end&amp;lt;/code&amp;gt; keyword. For better readability we indent the code inside the function using spaces or tabs.&amp;lt;br&amp;gt;&lt;br /&gt;
The print statement will not execute until the function is called.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function hello()&lt;br /&gt;
    print(&amp;quot;Hello function!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whenever you call a function by putting &amp;lt;code&amp;gt;()&amp;lt;/code&amp;gt; after the function name, all the code inside the function will run line by line first, before continuing with the rest of your code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(&amp;quot;Outside.&amp;quot;)&lt;br /&gt;
hello()&lt;br /&gt;
print(&amp;quot;Below hello.&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
This will output the following:&lt;br /&gt;
 Outside.&lt;br /&gt;
 Hello function!&lt;br /&gt;
 Below hello.&lt;br /&gt;
You can also give the function some values to work with by putting variable names inside the &amp;lt;code&amp;gt;()&amp;lt;/code&amp;gt;. These variables are called parameters. The function can also return a new value itself that is accessible from where the function is called. If no &amp;lt;code&amp;gt;return&amp;lt;/code&amp;gt; is specified, the function returns &amp;lt;code&amp;gt;nil&amp;lt;/code&amp;gt; (see &amp;quot;Types&amp;quot; section below).&amp;lt;br&amp;gt;&lt;br /&gt;
Here is an example of a function that calculates the sum of two numbers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function sum(a,b)    -- parameters seperated by commas&lt;br /&gt;
    local s = a + b  -- calculate the sum&lt;br /&gt;
    return s         -- return the sum to be used by tha caller&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local var1 = 2&lt;br /&gt;
local var2 = 8&lt;br /&gt;
local var3 = sum(var1, var2) -- call the function and pass two variables. note that these do not have to be called a and b&lt;br /&gt;
print(var3) --&amp;gt; 10, as you might have noticed, `print` is also a function that takes a parameter&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Values==&lt;br /&gt;
Values represent some form of data.&amp;lt;br&amp;gt;&lt;br /&gt;
There are many types of values for storing different types of data.&lt;br /&gt;
&lt;br /&gt;
===boolean===&lt;br /&gt;
A boolean is a data type with 2 distinct values: &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Most operators return a boolean and it&amp;#039;s current state can be inverted with &amp;lt;code&amp;gt;not&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;syntaxHighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local a = true&lt;br /&gt;
print(a) --&amp;gt; true&lt;br /&gt;
print(not a) --&amp;gt; false&lt;br /&gt;
a = not a -- a = false&lt;br /&gt;
print(a) --&amp;gt; false&lt;br /&gt;
print(not a) --&amp;gt; true&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
===number===&lt;br /&gt;
A number is, well, a number.&amp;lt;br&amp;gt;&lt;br /&gt;
Numbers can use arithmetic operators.&lt;br /&gt;
&amp;lt;syntaxHighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local a = 14&lt;br /&gt;
local b = 4&lt;br /&gt;
print(a+b) --&amp;gt; 18&lt;br /&gt;
print(a-b) --&amp;gt; 10&lt;br /&gt;
print(a*b) --&amp;gt; 56&lt;br /&gt;
print(a/b) --&amp;gt; 3.5&lt;br /&gt;
print(a%b) --&amp;gt; 2&lt;br /&gt;
local c = 3.1459&lt;br /&gt;
local d = math.pi&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
===string===&lt;br /&gt;
A string is a sequence of characters.&amp;lt;br&amp;gt;&lt;br /&gt;
Mostly used for holding and manipulating text data.&lt;br /&gt;
&lt;br /&gt;
[https://www.lua.org/manual/5.2/manual.html#6.4 String functions] are accessible through the &amp;lt;code&amp;gt;string&amp;lt;/code&amp;gt; global variable. All string values also contain these functions within themselves.&lt;br /&gt;
&lt;br /&gt;
Strings are defined by encasing text in double quotes (&amp;lt;code&amp;gt;&amp;quot;&amp;lt;/code&amp;gt;) or single quotes (&amp;lt;code&amp;gt;&amp;#039;&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
If you try to put a newline in a string, Lua will refuse and throw a syntax error. Newlines must be encoded into a string using other characters. Specifically &amp;lt;code&amp;gt;\n&amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
If you need to have either a &amp;lt;code&amp;gt;&amp;quot;&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;&amp;#039;&amp;lt;/code&amp;gt; in a string and you cannot wrap the string in another quote type, you can escape the quote using &amp;lt;code&amp;gt;\&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Long Strings are defined by encasing text in 2 square brackets (&amp;lt;code&amp;gt;[[]]&amp;lt;/code&amp;gt;). Long strings capture every single character between the pairs of square brackets including raw newlines.&lt;br /&gt;
&amp;lt;syntaxHighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local str = &amp;quot;foo&amp;quot;&lt;br /&gt;
print(str .. &amp;quot; bar&amp;quot;)                          --&amp;gt; foo bar&lt;br /&gt;
&lt;br /&gt;
local a = &amp;quot;This string has \&amp;quot;quotes\&amp;quot; in it.&amp;quot;&lt;br /&gt;
print(a)                                       --&amp;gt; This string has &amp;quot;quotes&amp;quot; in it.&lt;br /&gt;
&lt;br /&gt;
local b = &amp;quot;This will result in&lt;br /&gt;
a syntax error&amp;quot;&lt;br /&gt;
&lt;br /&gt;
local c = &amp;quot;This \nwill \nnot&amp;quot;&lt;br /&gt;
&lt;br /&gt;
local d = [[neither &lt;br /&gt;
will &lt;br /&gt;
this]]&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
===table===&lt;br /&gt;
A Lua table is a data structure that stores many values.&lt;br /&gt;
&lt;br /&gt;
Tables operate on key-value pairs. You give the table a key in the form of a value, and it returns a value.&amp;lt;br&amp;gt;&lt;br /&gt;
Assigning works the same way. Give the table a key, and assign a value to the table at that key.&lt;br /&gt;
&amp;lt;syntaxHighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Define an empty table&lt;br /&gt;
local tbl = {}&lt;br /&gt;
-- Store the value 23 in the table with the key 54&lt;br /&gt;
tbl[54] = 23&lt;br /&gt;
-- Store the value false in the table with the key &amp;quot;stringKey&amp;quot;&lt;br /&gt;
tbl[&amp;quot;stringKey&amp;quot;] = false&lt;br /&gt;
&lt;br /&gt;
-- variables can be inputted, using their value as the key.&lt;br /&gt;
-- For instance, let&amp;#039;s use our global c (which, if you don&amp;#039;t remember, was set to 10) from earlier.&lt;br /&gt;
tbl[c] = &amp;quot;123&amp;quot;&lt;br /&gt;
&lt;br /&gt;
tbl[67] = tbl[54]&lt;br /&gt;
&lt;br /&gt;
print(tbl[54]) --&amp;gt; 23&lt;br /&gt;
print(tbl[&amp;quot;stringKey&amp;quot;]) --&amp;gt; false&lt;br /&gt;
print(tbl[10]) --&amp;gt; &amp;quot;123&amp;quot;&lt;br /&gt;
print(tbl[67]) --&amp;gt; 23&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
If your key is a string, you can use a different way of indexing that is easier to do. Do note that only strings that abide by identifier rules can be used this way. If the string is not a valid identifier, use &amp;lt;code&amp;gt;[]&amp;lt;/code&amp;gt; indexing&lt;br /&gt;
&amp;lt;syntaxHighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local data={}&lt;br /&gt;
data.name=&amp;quot;Chocolate&amp;quot;&lt;br /&gt;
data.amount=100&lt;br /&gt;
data.delicious=true&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
Unlike other values which are passed around by value, tables are passed by reference.&amp;lt;br&amp;gt;&lt;br /&gt;
What this means is that when you create a table and assign it to a variable, then assign it to a different variable, you do not have 2 tables. You have 2 variables pointing to the same table.&lt;br /&gt;
&amp;lt;syntaxHighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local a = {}&lt;br /&gt;
local b = a&lt;br /&gt;
local c = {}&lt;br /&gt;
print(a) --&amp;gt; table4b8ab37d&lt;br /&gt;
print(b) --&amp;gt; table4b8ab37d&lt;br /&gt;
print(c) --&amp;gt; table82f1e9c2&lt;br /&gt;
-- table equality works on &amp;quot;is this the same table?&amp;quot;.&lt;br /&gt;
-- The values inside do not matter.&lt;br /&gt;
print(a == b) --&amp;gt; true&lt;br /&gt;
print(a == c) --&amp;gt; false&lt;br /&gt;
-- same table in memory.&lt;br /&gt;
a.reeee = 2&lt;br /&gt;
print(b.reeee) --&amp;gt; 2&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===nil===&lt;br /&gt;
&amp;lt;code&amp;gt;nil&amp;lt;/code&amp;gt; is commonly referred to as the absence of data.&amp;lt;br&amp;gt;&lt;br /&gt;
It is what is returned when no data is present.&lt;br /&gt;
&lt;br /&gt;
===function===&lt;br /&gt;
Yes, functions are also a type of variable.&lt;br /&gt;
&lt;br /&gt;
An alternative way to name a function to what we learned before is by assigning a function to a variable.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local a = function()&lt;br /&gt;
    print(&amp;quot;function was called&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is functionally the same thing as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local function a()&lt;br /&gt;
    print(&amp;quot;function was called&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Like tables, functions are passed by reference, and equality is based on &amp;quot;is this the same function?&amp;quot;. The actual contents of the function are not evaluated, so identical looking functions, while similar, are not equal.&lt;br /&gt;
&amp;lt;syntaxHighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local a=print&lt;br /&gt;
print(a == print) --&amp;gt; true&lt;br /&gt;
&lt;br /&gt;
local b=function() end&lt;br /&gt;
local c=function() end&lt;br /&gt;
print(b == c) --&amp;gt; false&lt;br /&gt;
&lt;br /&gt;
c = b&lt;br /&gt;
print(b == c) --&amp;gt; true&lt;br /&gt;
&lt;br /&gt;
print(b()) --&amp;gt; nil, because b does not return anything&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since functions are just another value type, they can be used as arguments to other functions.&lt;br /&gt;
&amp;lt;syntaxHighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local function do10(func)&lt;br /&gt;
    for i=1,10 do -- this just means &amp;quot;repeat 10 times&amp;quot; increasing the variable `i` every time&lt;br /&gt;
        func(i)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
do10(print) --&amp;gt; 1,2,3,4,5,6,7,8,9,10&lt;br /&gt;
do10(function(v)&lt;br /&gt;
    print(v*2)&lt;br /&gt;
end) --&amp;gt; 2,4,6,8,10,12,14,16,18,20&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
Functions have access to all variables defined above where the function gets defined. Variables below where the function is defined is considered &amp;quot;out of scope&amp;quot; of the function.&amp;lt;br&amp;gt;&lt;br /&gt;
If a variable is used that is not defined above the function, the global variable with that identifier will be used&lt;br /&gt;
&amp;lt;syntaxHighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local a = 10&lt;br /&gt;
local b = &amp;quot;string lol&amp;quot;&lt;br /&gt;
local function d()&lt;br /&gt;
    print(a)&lt;br /&gt;
    print(b)&lt;br /&gt;
    print(c) -- there is no `c` variable defined above here, so the global `c` will be used.&lt;br /&gt;
end&lt;br /&gt;
local c = 20&lt;br /&gt;
d()&lt;br /&gt;
--&amp;gt; 10&lt;br /&gt;
--&amp;gt; &amp;quot;string lol&amp;quot;&lt;br /&gt;
--&amp;gt; 10&lt;br /&gt;
-- If you forgot the countless times we&amp;#039;ve used the global c through this entire page, c is still 10.&lt;br /&gt;
&lt;br /&gt;
local function e(b)&lt;br /&gt;
    print(a)&lt;br /&gt;
    print(b)    -- variable `b` is redefined as a function parameter, so the other `b` is scope gets overshadowed&lt;br /&gt;
    print(c)    -- There *is* a `c` variable within scope this time&lt;br /&gt;
end&lt;br /&gt;
e(&amp;quot;string kek&amp;quot;)&lt;br /&gt;
--&amp;gt; 10&lt;br /&gt;
--&amp;gt; &amp;quot;string kek&amp;quot;&lt;br /&gt;
--&amp;gt; 20&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
If a function is one of the values in a table, special syntax can be used to have the table itself be the first argument to the function. By indexing the function with colon (&amp;lt;code&amp;gt;:&amp;lt;/code&amp;gt;) Lua will put the table itself as the first argument.&lt;br /&gt;
&lt;br /&gt;
This is used heavily in Figura for many of its APIs. All objects of the same type share the exact same functions, differentiated only by the object placed in the first argument.&lt;br /&gt;
&amp;lt;syntaxHighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local tbl={}&lt;br /&gt;
tbl.key = function(t, a, b)&lt;br /&gt;
    t[a] = b&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
tbl:key(&amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
-- this is functionally equivalent&lt;br /&gt;
tbl.key(tbl, &amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
-- You can also use `:` when creating functions. The implied `self` argument will be used to refer to the first argument&lt;br /&gt;
function tbl:key(a, b)&lt;br /&gt;
    self[a] = b&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
===userdata===&lt;br /&gt;
Lua is commonly used when embedded in other software. In this case, it is embedded inside of Figura.&amp;lt;br&amp;gt;&lt;br /&gt;
userdata is the means of communicating with that software.&lt;br /&gt;
&lt;br /&gt;
userdata is basically data initialized in Figura that gets interpreted as a Lua value. They function most similar to tables in the fact that they are indexed the same way to receive values, mostly functions.&lt;br /&gt;
&lt;br /&gt;
This is why knowing when to use `:` to index userdata is important.&lt;br /&gt;
&amp;lt;syntaxHighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- `models` is a value of type userdata. More specifically, it is a ModelPart created in Java and made accessible in Lua.&lt;br /&gt;
-- userdata commonly overrides what the print and tostring functions return to improve the ability to debug code.&lt;br /&gt;
print(models) --&amp;gt; models (ModelPart)&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
==Variable Scope==&lt;br /&gt;
A Variable&amp;#039;s Scope is the area the variable is accessible from.&lt;br /&gt;
&lt;br /&gt;
A variable&amp;#039;s scope begins when it is declared, and extends until the end of the current block.&amp;lt;br&amp;gt;&lt;br /&gt;
The scope of global variables is the Lua environment itself and will not clear until Lua itself is shut down.&lt;br /&gt;
&lt;br /&gt;
All [[#control_statements|control statements]] will create new scopes when used. Functions also create their on scope when declared&amp;lt;br&amp;gt;&lt;br /&gt;
The `do end` statement can be used to create scopes, and doesn&amp;#039;t have any other functionality. I will be using it to showcase how scopes affect variables, as explaining it raw will not get the point across. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local a=4&lt;br /&gt;
local b=8&lt;br /&gt;
do&lt;br /&gt;
    -- a and b are accessible here&lt;br /&gt;
    local c = 12&lt;br /&gt;
    -- a, b, and c are accessible here&lt;br /&gt;
    a = 16 -- variable `a` in the outer scope is now `16`&lt;br /&gt;
&lt;br /&gt;
    local b = 20 -- b in the other scope has been overshadowed by this variable. All future references to `b` will refer to this variable (until the end of the scope)&lt;br /&gt;
&lt;br /&gt;
    print(a,b,c,d) --&amp;gt; 16, 20, 12, nil&lt;br /&gt;
end&lt;br /&gt;
print(a,b,c,d) --&amp;gt; 16, 8, 10, nil&lt;br /&gt;
-- Global c is still 10.&lt;br /&gt;
&lt;br /&gt;
local e&lt;br /&gt;
do&lt;br /&gt;
    local f=0&lt;br /&gt;
&lt;br /&gt;
    -- interesting thing is that functions capture the current scope.&lt;br /&gt;
    -- Even if we leave the scope, the function remembers the upvalue `f` and will continue to use it even if the scope `f` belongs to ends&lt;br /&gt;
    -- oh yea `a` is overshadowed here too. But thats not as interesting.&lt;br /&gt;
    e=function(a)&lt;br /&gt;
        f=f+1&lt;br /&gt;
        print(f, a)&lt;br /&gt;
    end&lt;br /&gt;
    e()--&amp;gt; 1, nil&lt;br /&gt;
    e()--&amp;gt; 2, nil&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
e()    --&amp;gt; 3, nil&lt;br /&gt;
e(&amp;quot;a&amp;quot;) --&amp;gt; 4, &amp;quot;a&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
==Value Truthiness==&lt;br /&gt;
All values have an implicit truthiness when used in the context of a boolean.&lt;br /&gt;
&lt;br /&gt;
It&amp;#039;s simple to remember: &amp;lt;code&amp;gt;nil&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt; are both considered &amp;quot;falsely&amp;quot;, and every other value is considered &amp;quot;truthy&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Truthiness is used in control statements, see the section about it below.&lt;br /&gt;
&lt;br /&gt;
==Operators==&lt;br /&gt;
Operators, similar functions, take 1 or 2 values and outputs a result.&amp;lt;br&amp;gt;&lt;br /&gt;
They commonly take the form &amp;lt;code&amp;gt;leftSide operator rightSide&amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
I will continue to refer to the 2 values that operators operate on as &amp;lt;code&amp;gt;leftSide&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;rightSide&amp;lt;/code&amp;gt; for the duration of this section.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Operators have a priority system. It is surprisingly intuitive, but can be forced by surrounding the code you want to guarantee execute first in brackets `()`. For the true priority list, check out the [https://www.lua.org/manual/5.2/manual.html#3.4.7 Lua Reference Manual].&lt;br /&gt;
&lt;br /&gt;
Do note that despite me saying that &amp;quot;Only x can use this operator&amp;quot;, tables and userdata types are always exempt from this rule. However, they must be explicitly written to support these operators, so most will not support it by default.&lt;br /&gt;
===Arithmetic Addition (+)===&lt;br /&gt;
Its addition. 1+1 returns 2. Basic stuff.&amp;lt;br&amp;gt;&lt;br /&gt;
Only numbers can use this operator.&lt;br /&gt;
===Arithmetic Subtraction (-)===&lt;br /&gt;
Its subtraction. 2-3 returns -1. Basic stuff.&amp;lt;br&amp;gt;&lt;br /&gt;
Only numbers can use this operator.&lt;br /&gt;
===Arithmetic Multiplication (*)===&lt;br /&gt;
Its multiplication. 2*4 returns 8. Basic stuff.&amp;lt;br&amp;gt;&lt;br /&gt;
Only numbers can use this operator.&lt;br /&gt;
===Arithmetic Division (/)===&lt;br /&gt;
Its division. 5/2 returns 2.5. Basic stuff.&amp;lt;br&amp;gt;&lt;br /&gt;
Only numbers can use this operator.&lt;br /&gt;
===Arithmetic Modulo (%)===&lt;br /&gt;
Division actually has 2 components. The whole component, and the remainder component.&amp;lt;br&amp;gt;&lt;br /&gt;
Modulo returns this remainder component after the division leftSide/rightSide is done.&amp;lt;br&amp;gt;&lt;br /&gt;
5%2 returns 1, because 2 goes into 5 2 whole times, 2*2=4, 5-4=1.&amp;lt;br&amp;gt;&lt;br /&gt;
Only numbers can use this operator.&lt;br /&gt;
===Arithmetic Exponentiation (^)===&lt;br /&gt;
Its exponents. 2^3 returns 8. Basic stuff.&amp;lt;br&amp;gt;&lt;br /&gt;
Only numbers can use this operator.&lt;br /&gt;
===Arithmetic Negation (-)===&lt;br /&gt;
Only operates on the rightSide.&amp;lt;br&amp;gt;&lt;br /&gt;
This operator negates the number, similar to just adding a negative symbol in front of it.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;syntaxHighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local a= -2&lt;br /&gt;
a=-a&lt;br /&gt;
print(a) --&amp;gt; 2&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
===Relational Equality (==)===&lt;br /&gt;
Returns `true` if both values are considered the same value, `false` otherwise.&amp;lt;br&amp;gt;&lt;br /&gt;
All values can use this operator.&lt;br /&gt;
===Relational Inequality (~=)===&lt;br /&gt;
Returns `false` if both values are considered the same value, `true` otherwise.&amp;lt;br&amp;gt;&lt;br /&gt;
All values can use this operator.&lt;br /&gt;
===Relational Less Than (&amp;lt;)===&lt;br /&gt;
Returns `true` if the leftSide is considered less then the rightSide, `false` otherwise.&amp;lt;br&amp;gt;&lt;br /&gt;
Numbers compare as expected.&lt;br /&gt;
Strings compare using their ascii representations, comparing each character left to right until they are not equal. Then the operator is applied to those 2 character&amp;#039;s ascii numbers and returned.&lt;br /&gt;
===Relational Greater Than (&amp;gt;)===&lt;br /&gt;
Returns `true` if the leftSide is considered greater then the rightSide, `false` otherwise.&amp;lt;br&amp;gt;&lt;br /&gt;
Numbers compare as expected.&lt;br /&gt;
Strings compare using their ascii representations, comparing each character left to right until they are not equal. Then the operator is applied to those 2 character&amp;#039;s ascii numbers and returned.&lt;br /&gt;
===Relational Less Than or Equal To (&amp;lt;=)===&lt;br /&gt;
Returns `true` if the leftSide is considered less then or equal to the rightSide using equality operator rules, `false` otherwise.&amp;lt;br&amp;gt;&lt;br /&gt;
Numbers compare as expected.&lt;br /&gt;
Strings compare using their ascii representations, comparing each character left to right until they are not equal. Then the operator is applied to those 2 character&amp;#039;s ascii numbers and returned.&lt;br /&gt;
===Relational Greater Than or Equal To (&amp;gt;=)===&lt;br /&gt;
Returns `true` if the leftSide is considered greater then or equal to the rightSide using equality operator rules, `false` otherwise.&amp;lt;br&amp;gt;&lt;br /&gt;
Numbers compare as expected.&lt;br /&gt;
Strings compare using their ascii representations, comparing each character left to right until they are not equal. Then the operator is applied to those 2 character&amp;#039;s ascii numbers and returned.&lt;br /&gt;
===Logical And (and)===&lt;br /&gt;
This operator operates on truthiness.&amp;lt;br&amp;gt;&lt;br /&gt;
If the leftSide is considered truthy, it returns the rightSide. Otherwise, it returns the leftSide.&amp;lt;br&amp;gt;&lt;br /&gt;
This ends up with the return value being truthy only if both leftSide &amp;#039;&amp;#039;and&amp;#039;&amp;#039; rightSide are truthy.&amp;lt;br&amp;gt;&lt;br /&gt;
The following table puts this visually. L is leftSide, R is rightSide. F and T represent if the value is falsy or truthy, and the column under O represents which value actually gets returned by `and` as well as the truthiness of it.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Left !! Right !! Output&lt;br /&gt;
|-&lt;br /&gt;
| False || False || False (Left)&lt;br /&gt;
|-&lt;br /&gt;
| False || True || False (Left)&lt;br /&gt;
|-&lt;br /&gt;
| True || False || False (Right)&lt;br /&gt;
|-&lt;br /&gt;
| True || True || True (Right)&lt;br /&gt;
|}&lt;br /&gt;
The reason this is so complex is because it doesn&amp;#039;t just work on booleans. It works on all value types.&lt;br /&gt;
&lt;br /&gt;
===Logical Or (or)===&lt;br /&gt;
This operator operates on truthiness.&amp;lt;br&amp;gt;&lt;br /&gt;
If the leftSide is considered truthy, it returns the leftSide. Otherwise, it returns the rightSide.&amp;lt;br&amp;gt;&lt;br /&gt;
This ends up with the return value being truthy either the leftSide &amp;#039;&amp;#039;or&amp;#039;&amp;#039; rightSide are truthy.&amp;lt;br&amp;gt;&lt;br /&gt;
The following table puts this visually. L is leftSide, R is rightSide. F and T represent if the value is falsy or truthy, and the column under O represents which value actually gets returned by `or` as well as the truthiness of it.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Left !! Right !! Output&lt;br /&gt;
|-&lt;br /&gt;
| False || False || False (Right)&lt;br /&gt;
|-&lt;br /&gt;
| False || True || True (Right)&lt;br /&gt;
|-&lt;br /&gt;
| True || False || True (Left)&lt;br /&gt;
|-&lt;br /&gt;
| True || True || True (Left)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The reason this is so complex is because it doesn&amp;#039;t just work on booleans. It works on all value types.&lt;br /&gt;
&lt;br /&gt;
===Logical Not (not)===&lt;br /&gt;
Only operates on the rightSide.&amp;lt;br&amp;gt;&lt;br /&gt;
This operator evaluates the truthiness of the value, then returns the boolean representation of the opposite.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;not true&amp;lt;/code&amp;gt; is &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;not 2&amp;lt;/code&amp;gt; is &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;not false&amp;lt;/code&amp;gt; is &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;not {}&amp;lt;/code&amp;gt; is &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;not nil&amp;lt;/code&amp;gt; is &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
All values can use this operator.&lt;br /&gt;
===String Concatenation (..)===&lt;br /&gt;
This returns a string from the values concatenated together.&amp;lt;br&amp;gt;&lt;br /&gt;
Only strings can use this operator.&lt;br /&gt;
===Length Operator (#)===&lt;br /&gt;
Only operates on the rightSide.&amp;lt;br&amp;gt;&lt;br /&gt;
This returns the length of the value&amp;lt;br&amp;gt;&lt;br /&gt;
For strings, its the amount of bytes stored in the string. (UTF-8 characters are more than one byte)&amp;lt;br&amp;gt;&lt;br /&gt;
For tables, lua iterates over &amp;lt;code&amp;gt;t[1], t[2], t[3] ... t[n]&amp;lt;/code&amp;gt; until a nil value is found and returns the number of non-nil values found.&lt;br /&gt;
&lt;br /&gt;
==Control Statements==&lt;br /&gt;
Control Statements affect the scope and flow of the program. &lt;br /&gt;
===&amp;lt;code&amp;gt;if then end&amp;lt;/code&amp;gt;===&lt;br /&gt;
&amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statements allow for executing code only when a condition is met.&lt;br /&gt;
&lt;br /&gt;
The basic structure looks like&lt;br /&gt;
&amp;lt;syntaxHighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
if condition then&lt;br /&gt;
    print(&amp;quot;condition is true&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statements have an optional &amp;lt;code&amp;gt;elseif&amp;lt;/code&amp;gt; clause, where if the previous condition failed this condition will be checked. In an &amp;lt;code&amp;gt;elseif&amp;lt;/code&amp;gt; chain, only the first successful condition will actually execute, after which all other &amp;lt;code&amp;gt;elseif&amp;lt;/code&amp;gt;s are ignored.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
if condition then&lt;br /&gt;
    print(&amp;quot;condition&amp;quot;)&lt;br /&gt;
elseif condition2 then&lt;br /&gt;
    print(&amp;quot;condition2&amp;quot;)&lt;br /&gt;
elseif condition3 then&lt;br /&gt;
    print(&amp;quot;condition3&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statements also have an optional &amp;lt;code&amp;gt;else&amp;lt;/code&amp;gt; clause, where if &amp;#039;&amp;#039;all&amp;#039;&amp;#039; previous conditions fail, the &amp;lt;code&amp;gt;else&amp;lt;/code&amp;gt; clause will execute.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
if condition then&lt;br /&gt;
    print(&amp;quot;condition&amp;quot;)&lt;br /&gt;
else&lt;br /&gt;
    print(&amp;quot;not condition&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
if condition then&lt;br /&gt;
    print(&amp;quot;condition&amp;quot;)&lt;br /&gt;
elseif condition2 then&lt;br /&gt;
    print(&amp;quot;condition2&amp;quot;)&lt;br /&gt;
else&lt;br /&gt;
    print(&amp;quot;not condition or condition2&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;else&amp;lt;/code&amp;gt; statements operate on [[#value_truthiness|Value Truthiness]]&lt;br /&gt;
&amp;lt;syntaxHighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local rand = math.random()&amp;lt;0.3&lt;br /&gt;
-- Use booleans as raw input to if statements&lt;br /&gt;
-- the `==` operator just returns a boolean anyways and is just wasted instructions&lt;br /&gt;
if rand then&lt;br /&gt;
    print(&amp;quot;random print statement lol&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- getVehicle returns either an Entity userdata, or nil&lt;br /&gt;
local vehicle=player:getVehicle()&lt;br /&gt;
if vehicle then&lt;br /&gt;
    print(&amp;quot;Riding: &amp;quot;, vehicle:getName())&lt;br /&gt;
else&lt;br /&gt;
    print(&amp;quot;No Mount&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Loops===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
for i=1,10 do&lt;br /&gt;
    print(i)&lt;br /&gt;
end&lt;br /&gt;
--&amp;gt; 1,2,3,4,5,6,7,8,9,10&lt;br /&gt;
&lt;br /&gt;
local x = 1&lt;br /&gt;
while x &amp;lt; 10 do&lt;br /&gt;
    x = x + 1&lt;br /&gt;
    print(x)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
--TODO this has been sitting locally for several months. I&amp;#039;m uploading it and finishing it later&lt;/div&gt;</summary>
		<author><name>Slyme</name></author>
	</entry>
</feed>