<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.starfall.wtf/index.php?action=history&amp;feed=atom&amp;title=Conditional_statements</id>
	<title>Conditional statements - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.starfall.wtf/index.php?action=history&amp;feed=atom&amp;title=Conditional_statements"/>
	<link rel="alternate" type="text/html" href="https://wiki.starfall.wtf/index.php?title=Conditional_statements&amp;action=history"/>
	<updated>2026-07-28T17:08:36Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://wiki.starfall.wtf/index.php?title=Conditional_statements&amp;diff=474&amp;oldid=prev</id>
		<title>PRG: Created page with &quot;__TOC__  ==Introduction== This guide is for absolute beginners. It is intended to familiarize you with conditionals, or Conditional statements, in Lua. If you haven&#039;t already, please see Your first script as a beginner tutorial.  == What this tutorial will teach you ==  * What conditional statements are * Certain types of conditional statements * How to use conditional statements  == Setup ==  You will need to open Roblox Studio.  Once you have done that, you wil...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.starfall.wtf/index.php?title=Conditional_statements&amp;diff=474&amp;oldid=prev"/>
		<updated>2024-12-10T22:10:04Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;__TOC__  ==Introduction== This guide is for absolute beginners. It is intended to familiarize you with conditionals, or Conditional statements, in Lua. If you haven&amp;#039;t already, please see &lt;a href=&quot;/index.php/Your_first_script&quot; title=&quot;Your first script&quot;&gt;Your first script&lt;/a&gt; as a beginner tutorial.  == What this tutorial will teach you ==  * What conditional statements are * Certain types of conditional statements * How to use conditional statements  == Setup ==  You will need to open &lt;a href=&quot;/index.php/Roblox_Studio&quot; class=&quot;mw-redirect&quot; title=&quot;Roblox Studio&quot;&gt;Roblox Studio&lt;/a&gt;.  Once you have done that, you wil...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
This guide is for absolute beginners. It is intended to familiarize you with conditionals, or Conditional statements, in Lua. If you haven&amp;#039;t already, please see [[Your first script]] as a beginner tutorial.&lt;br /&gt;
&lt;br /&gt;
== What this tutorial will teach you ==&lt;br /&gt;
&lt;br /&gt;
* What conditional statements are&lt;br /&gt;
* Certain types of conditional statements&lt;br /&gt;
* How to use conditional statements&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
You will need to open [[Roblox Studio]].  Once you have done that, you will need to click &amp;quot;My ROBLOX&amp;quot;, select your map, and click &amp;quot;Edit&amp;quot;. At this point, you should see your familiar map. &lt;br /&gt;
&lt;br /&gt;
You will need some essentials in [[Roblox Studio]] to make this work:&lt;br /&gt;
&lt;br /&gt;
* The Output window:&lt;br /&gt;
[[Image:Outputwindow.JPG]]&lt;br /&gt;
* The Explorer window:&lt;br /&gt;
[[Image:Explorerwindow.JPG]]&lt;br /&gt;
and &lt;br /&gt;
* The Command bar:&lt;br /&gt;
[[Image:Commandtoolbar.JPG]]&lt;br /&gt;
&lt;br /&gt;
* To make sure you have the Output window, click View / Output.&lt;br /&gt;
* To make sure you have the Explorer window visible, click View / Explorer.&lt;br /&gt;
* To make sure you have the Command bar visible, click View / Toolbars / Command.&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Conditional statements are a way of responding differently based on the result of a comparison, called a conditional expression.&amp;quot;[http://wiki.garrysmod.com/wiki/?title=Basic_Lua#Conditionals] &lt;br /&gt;
&lt;br /&gt;
This means that you are comparing the value of two (or more) things.  Let&amp;#039;s suppose we want Roblox &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; (2+3) is equal to 5, &amp;lt;b&amp;gt;then&amp;lt;/b&amp;gt; tell us that (2+3) == 5 &amp;lt;b&amp;gt;.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lua is similar to human language in this regard, we type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; (2+3) == 5 &amp;lt;b&amp;gt;then&amp;lt;/b&amp;gt; print (&amp;quot;(2+3)==5&amp;quot;) &amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Always end an if/then statement with &amp;quot;end&amp;quot;.  &amp;quot;End&amp;quot; is like a period to a sentence.&lt;br /&gt;
&lt;br /&gt;
An illustration of this in a flowchart would be:&lt;br /&gt;
&lt;br /&gt;
[[Image:Ifflowchart.JPG]]&lt;br /&gt;
&lt;br /&gt;
Here&amp;#039;s another example.  Let&amp;#039;s evaluate &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; (10-2) is greater than 3, &amp;lt;b&amp;gt;then&amp;lt;/b&amp;gt; tell us that (10-2) &amp;gt; 3 &amp;lt;b&amp;gt;.&amp;lt;/b&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; (10-2) &amp;gt; 3 &amp;lt;b&amp;gt;then&amp;lt;/b&amp;gt; print (&amp;quot;(10-2)&amp;gt;3&amp;quot;) &amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One last example.  Evaluate &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; 100 is not equal to 4, &amp;lt;b&amp;gt;then&amp;lt;/b&amp;gt; tell us that (100~=4)&amp;lt;b&amp;gt;.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; 100~=4 &amp;lt;b&amp;gt;then&amp;lt;/b&amp;gt; print (&amp;quot;100~=4&amp;quot;) &amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scripting ==&lt;br /&gt;
&lt;br /&gt;
Open [[Roblox Studio]] and make sure that there aren&amp;#039;t any other scripts in the [[Explorer]] window.  We&amp;#039;re going to start off with a fresh script.  &lt;br /&gt;
&lt;br /&gt;
* Click Workspace in the Explorer Window.&lt;br /&gt;
* Click Insert &amp;gt; Object &amp;gt; Script&lt;br /&gt;
* Double click the newly inserted script.&lt;br /&gt;
* A blank window should open up.&lt;br /&gt;
* Insert the following script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if (2+3) == 5 then print (&amp;quot;(2+3)==5&amp;quot;) end&lt;br /&gt;
if 5 &amp;gt; 2 then print (&amp;quot;5&amp;gt;2&amp;quot;) end&lt;br /&gt;
if 2 &amp;lt; 5 then print (&amp;quot;2&amp;lt;5&amp;quot;) end&lt;br /&gt;
if 5 &amp;gt;= 5 then print (&amp;quot;5&amp;gt;=5&amp;quot;) end&lt;br /&gt;
if 5 &amp;lt;= 5 then print (&amp;quot;5&amp;lt;=5&amp;quot;) end&lt;br /&gt;
if 1 ~= 100 then print (&amp;quot;1~=100&amp;quot;) end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Test the script by pressing the play button [[Image:Play.JPG]]&lt;br /&gt;
* Your Output bar should show:&lt;br /&gt;
&amp;lt;b&amp;gt;(2+3)==5&amp;lt;/b&amp;gt; (because 5 is equal to 5)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;5&amp;gt;2&amp;lt;/b&amp;gt; (because 5 is greater than 2)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;2&amp;lt;5&amp;lt;/b&amp;gt; (because 2 is less than 5)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;5&amp;gt;=5&amp;lt;/b&amp;gt; (because 5 is greater than or equal to 5)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;5&amp;lt;=5&amp;lt;/b&amp;gt; (because 5 is less than or equal to 5)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;1~=100&amp;lt;/b&amp;gt; (because 1 is not equal to 100)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Else ==&lt;br /&gt;
&lt;br /&gt;
What happens if your statement is &amp;lt;b&amp;gt;not&amp;lt;/b&amp;gt; true?  That&amp;#039;s when we can use an &amp;quot;else&amp;quot; statement.  The &amp;lt;b&amp;gt;&amp;quot;else&amp;quot;&amp;lt;/b&amp;gt; statement is similar to &amp;quot;otherwise&amp;quot; in English.  For example, &amp;quot;&amp;lt;b&amp;gt;If&amp;lt;/b&amp;gt; it is raining, bring an umbrella, otherwise (i.e., &amp;lt;b&amp;gt;else&amp;lt;/b&amp;gt;) bring your suntan lotion.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s see this as applied to scripting:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if 10&amp;gt;100 &lt;br /&gt;
then &lt;br /&gt;
	print(&amp;quot;10 is greater than 100&amp;quot;) &lt;br /&gt;
else &lt;br /&gt;
	print(&amp;quot;10 is less than 100&amp;quot;) &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since 10&amp;gt;100 is false, the &amp;lt;b&amp;gt;then&amp;lt;/b&amp;gt; statement won&amp;#039;t execute, but the &amp;lt;b&amp;gt;else&amp;lt;/b&amp;gt; statement will.&lt;br /&gt;
&lt;br /&gt;
[[Image:Ifelseflowchart.JPG]]&lt;br /&gt;
&lt;br /&gt;
== Elseif ==&lt;br /&gt;
&lt;br /&gt;
If you want to execute a script if one of several conditions are true, we can use the &amp;lt;b&amp;gt;elseif&amp;lt;/b&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&amp;lt;b&amp;gt;If&amp;lt;/b&amp;gt; it is raining, bring your umbrella.  &amp;lt;b&amp;gt;Otherwise, if&amp;lt;/b&amp;gt; (i.e., &amp;quot;elseif&amp;quot;) it isn&amp;#039;t raining, bring your suntan lotion.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Since either &amp;quot;it is raining&amp;quot; or &amp;quot;it isn&amp;#039;t raining&amp;quot; will be true, we can use the &amp;quot;elseif&amp;quot; statement.  Let&amp;#039;s try that in a script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if 10&amp;gt;100 &lt;br /&gt;
then &lt;br /&gt;
	print(&amp;quot;10 is greater than 100&amp;quot;) &lt;br /&gt;
&lt;br /&gt;
elseif (10&amp;gt;50)&lt;br /&gt;
then	&lt;br /&gt;
	print(&amp;quot;10 is greater than 50&amp;quot;) &lt;br /&gt;
&lt;br /&gt;
elseif (10&amp;lt;100)&lt;br /&gt;
then	&lt;br /&gt;
	print(&amp;quot;10 is less than 100&amp;quot;) &lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The only instance that would be true is 10&amp;lt;100, which would result in the printing of &amp;quot;10 is less than 100&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Image:Elseif.JPG]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Scripting Tutorials]]&lt;/div&gt;</summary>
		<author><name>PRG</name></author>
	</entry>
</feed>