<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.gtaconnected.com/wiki/index.php?action=history&amp;feed=atom&amp;title=ScriptingTutorials%2FLuaTutorial</id>
	<title>ScriptingTutorials/LuaTutorial - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.gtaconnected.com/wiki/index.php?action=history&amp;feed=atom&amp;title=ScriptingTutorials%2FLuaTutorial"/>
	<link rel="alternate" type="text/html" href="https://wiki.gtaconnected.com/wiki/index.php?title=ScriptingTutorials/LuaTutorial&amp;action=history"/>
	<updated>2026-06-24T07:13:50Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.15</generator>
	<entry>
		<id>https://wiki.gtaconnected.com/wiki/index.php?title=ScriptingTutorials/LuaTutorial&amp;diff=3821&amp;oldid=prev</id>
		<title>Mex at 12:56, 14 August 2018</title>
		<link rel="alternate" type="text/html" href="https://wiki.gtaconnected.com/wiki/index.php?title=ScriptingTutorials/LuaTutorial&amp;diff=3821&amp;oldid=prev"/>
		<updated>2018-08-14T12:56:14Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{DISPLAYTITLE:Lua Tutorial}}&lt;br /&gt;
This page shows some of the functionality in Lua. Be sure to reference the [https://www.lua.org/manual/5.3/ official Lua manual] when you can.&lt;br /&gt;
==Comments==&lt;br /&gt;
{{LuaCode|1=-- this is a single line comment, which can appear at the end of any line}}&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{LuaCode|1=--[[&lt;br /&gt;
this is a multi line comment,&lt;br /&gt;
which can appear anywhere&lt;br /&gt;
]]&lt;br /&gt;
}}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Functions==&lt;br /&gt;
&lt;br /&gt;
{{LuaCode|1=someFunction() -- this is a call to a function named someFunction, the code for that function will run when the function is called}}&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{LuaCode|1=someFunction(5, 400, 5000) -- this is a call to a function, sending 3 parameters to it. a parameter is an input value for a function}}&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{LuaCode|1=-- this is a function definition, which is a portion of code, don&amp;#039;t forget the word end to end the function definition&lt;br /&gt;
function someFunction()&lt;br /&gt;
end}}&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{LuaCode|1=-- this is a function definition, which takes 3 parameters. parameters are also called arguments&lt;br /&gt;
function someFunction(arg1, arg2, arg3)&lt;br /&gt;
end}}&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{LuaCode|1=-- this is a function without a name, also known as a lambda function&lt;br /&gt;
function() end}}&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{LuaCode|1=-- this is a function which adds 2 numbers&lt;br /&gt;
-- the word return is used to set the output of the function, as well as to stop the function running at the expression after the word return&lt;br /&gt;
-- the result of add(..) is sent straight to the print function, print is a function provided by Lua&lt;br /&gt;
function add(a, b)&lt;br /&gt;
    return a + b&lt;br /&gt;
end&lt;br /&gt;
print(add(40, 20))&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Data Types==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;string&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
{{LuaCode|1=&amp;#039;this is a string&amp;#039;&lt;br /&gt;
&amp;quot;this is a string&amp;quot;&lt;br /&gt;
[[this is a string]]}}&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;number&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
{{LuaCode|1=20&lt;br /&gt;
40.0&lt;br /&gt;
99e5&lt;br /&gt;
-20&lt;br /&gt;
-40.0}}&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;boolean&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
{{LuaCode|1=true&lt;br /&gt;
false}}&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;nil&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
{{LuaCode|1=nil&lt;br /&gt;
&lt;br /&gt;
someVariable = nil -- delete a variable&lt;br /&gt;
&lt;br /&gt;
if someVariable == nil then -- comparison with nil&lt;br /&gt;
end}}&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;table&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
{{LuaCode|1={} -- an empty table&lt;br /&gt;
&lt;br /&gt;
{20, 50, 80} -- a table with 3 elements, keys are 1 2 and 3, values are 20 50 and 80, respectively.&lt;br /&gt;
&lt;br /&gt;
{aa=5, bb=10} -- a table with 2 elements, element with key aa has value 5, and element with key bb has value 10&lt;br /&gt;
&lt;br /&gt;
{[5]=&amp;#039;aa&amp;#039;, [10]=&amp;#039;bb&amp;#039;} -- a table with 2 elements, element with key 5 has value &amp;#039;aa&amp;#039;, and element with key 10 has value &amp;#039;bb&amp;#039;}}&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;function&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
{{LuaCode|1=function() end -- an empty function with no name&lt;br /&gt;
&lt;br /&gt;
function someFuncName() -- an empty function with a name&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
someFuncName = function() -- an empty function with a name&lt;br /&gt;
end}}&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are also data types &amp;#039;&amp;#039;&amp;#039;userdata&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;thread&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
==Operators==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Math Operators&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
{{LuaCode|1=+ - * / % -- these are mathematical operators&lt;br /&gt;
&lt;br /&gt;
5 * 4 -- results in 20&lt;br /&gt;
&lt;br /&gt;
5 * 4 + 2 -- results in 22&lt;br /&gt;
&lt;br /&gt;
5 * (4 + 2) -- results in 30}}&lt;br /&gt;
&lt;br /&gt;
==Variables==&lt;br /&gt;
&lt;br /&gt;
{{LuaCode|1=local someVariableName = &amp;#039;some string value&amp;#039; -- this creates a local variable and assigns it a string value&lt;br /&gt;
&lt;br /&gt;
someGlobalVariable = 50 -- this either creates a global variable, or updates an existing variable, and assigns it a number value&lt;br /&gt;
&lt;br /&gt;
_G.someGlobalVariable = 50 -- this is the same as the global variable above, however we are referencing the global namespace using _G, so the variable will definitely be global}}&lt;br /&gt;
&lt;br /&gt;
==Conditions==&lt;br /&gt;
&lt;br /&gt;
{{LuaCode|1=local someVariable = 500&lt;br /&gt;
&lt;br /&gt;
-- if&lt;br /&gt;
if someVariable &amp;lt; 1000 then&lt;br /&gt;
    print(&amp;#039;value is less than 1000&amp;#039;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- if and else&lt;br /&gt;
if someVariable &amp;lt; 200 then&lt;br /&gt;
    print(&amp;#039;value is less than 200&amp;#039;)&lt;br /&gt;
else&lt;br /&gt;
    print(&amp;#039;value is 200 or more&amp;#039;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- if, elseif and else&lt;br /&gt;
if someVariable &amp;lt; 100 then&lt;br /&gt;
    print(&amp;#039;value is less than 100&amp;#039;)&lt;br /&gt;
elseif someVariable &amp;lt; 300 then&lt;br /&gt;
    print(&amp;#039;value is less than 300&amp;#039;)&lt;br /&gt;
elseif someVariable &amp;lt; 500 then&lt;br /&gt;
    print(&amp;#039;value is less than 500&amp;#039;)&lt;br /&gt;
else&lt;br /&gt;
    print(&amp;#039;value is 500 or more&amp;#039;)&lt;br /&gt;
end}}&lt;br /&gt;
&lt;br /&gt;
==Loops==&lt;br /&gt;
&lt;br /&gt;
{{LuaCode|1=-- integer loop&lt;br /&gt;
for i=1, 20 do&lt;br /&gt;
    print(i)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- table loop&lt;br /&gt;
for i,v in ipairs({20,50,80}) do&lt;br /&gt;
    print(v)&lt;br /&gt;
end}}&lt;/div&gt;</summary>
		<author><name>Mex</name></author>
	</entry>
</feed>