<?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=Functions</id>
	<title>Functions - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.starfall.wtf/index.php?action=history&amp;feed=atom&amp;title=Functions"/>
	<link rel="alternate" type="text/html" href="https://wiki.starfall.wtf/index.php?title=Functions&amp;action=history"/>
	<updated>2026-07-28T16:17:10Z</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=Functions&amp;diff=485&amp;oldid=prev</id>
		<title>PRG: Created page with &quot;__TOC__  == Introduction == Functions perform specific tasks.  Some functions are already predefined, and some functions you create yourself.  The idea behind the functions is the same.  == Simple functions == Let&#039;s take a look at a simple function.  &lt;pre&gt; function myfunction() -- what this function does 	x=2+2 	print(x) end  myfunction() -- call the function  &lt;/pre&gt;  Everything between &lt;b&gt;function&lt;/b&gt; and &lt;b&gt;end&lt;/b&gt; simply describes what your function...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.starfall.wtf/index.php?title=Functions&amp;diff=485&amp;oldid=prev"/>
		<updated>2024-12-10T22:17:46Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;__TOC__  == Introduction == Functions perform specific tasks.  Some functions are already &lt;a href=&quot;/index.php/Function_Dump&quot; title=&quot;Function Dump&quot;&gt;predefined&lt;/a&gt;, and some functions you create yourself.  The idea behind the functions is the same.  == Simple functions == Let&amp;#039;s take a look at a simple function.  &amp;lt;pre&amp;gt; function myfunction() -- what this function does 	x=2+2 	print(x) end  myfunction() -- call the function  &amp;lt;/pre&amp;gt;  Everything between &amp;lt;b&amp;gt;function&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt; simply describes what your function...&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;
Functions perform specific tasks.  Some functions are already [[Function Dump|predefined]], and some functions you create yourself.  The idea behind the functions is the same.&lt;br /&gt;
&lt;br /&gt;
== Simple functions ==&lt;br /&gt;
Let&amp;#039;s take a look at a simple function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function myfunction() -- what this function does&lt;br /&gt;
	x=2+2&lt;br /&gt;
	print(x)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
myfunction() -- call the function &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Everything between &amp;lt;b&amp;gt;function&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;end&amp;lt;/b&amp;gt; simply describes what your function will do.  Here, you are&lt;br /&gt;
&lt;br /&gt;
* Allocating a value of 2+2 to x&lt;br /&gt;
* Printing x&lt;br /&gt;
&lt;br /&gt;
It&amp;#039;s important to note that your function &amp;lt;b&amp;gt;won&amp;#039;t&amp;lt;/b&amp;gt; run, i.e., you won&amp;#039;t see the value of &amp;quot;4&amp;quot; appear on your screen unless you specifically &amp;lt;b&amp;gt;call&amp;lt;/b&amp;gt; it.  That is what the last line is, namely:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
myfunction()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you delete this line, nothing will get printed to your screen.&lt;br /&gt;
&lt;br /&gt;
== Creating new bricks ==&lt;br /&gt;
&lt;br /&gt;
You can make a function do all kinds of things.  For example, the following function will create a new brick:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function newbrick()&lt;br /&gt;
local p = Instance.new(&amp;quot;Part&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
p.Parent = game.Workspace&lt;br /&gt;
p.Name = &amp;quot;Brick&amp;quot;&lt;br /&gt;
p.Anchored = true&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
newbrick()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, the function (called &amp;quot;newbrick()&amp;quot;) is creating a new [[Instance]] of a [[Part|brick]].  That brick will be in the [[Workspace]].  We are inserting a specific object, namely a [[Part]], and naming it &amp;quot;Brick&amp;quot;.  We want to [[Anchor]] it so the brick won&amp;#039;t fall down.&lt;br /&gt;
&lt;br /&gt;
Lastly, we call the function so that the function will execute.&lt;br /&gt;
&lt;br /&gt;
== Action-triggered functions ==&lt;br /&gt;
&lt;br /&gt;
Functions don&amp;#039;t have to be called by writing out a command.  They can be called by a human action, such as clicking a mouse button. &lt;br /&gt;
&lt;br /&gt;
* Insert &amp;gt; Object &amp;gt; Part&lt;br /&gt;
* [[Anchor]] that newly inserted brick.&lt;br /&gt;
* Click that brick.&lt;br /&gt;
* Insert &amp;gt; Object &amp;gt; [[ClickDetector]].  This will allow the brick to detect when it is being &amp;#039;clicked&amp;#039;.&lt;br /&gt;
* Insert &amp;gt; Object &amp;gt; Script.&lt;br /&gt;
* Double-click that script file, and insert the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function clickabrick()&lt;br /&gt;
print(&amp;quot;Hi mom!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
  &lt;br /&gt;
script.Parent.ClickDetector.MouseClick:connect(clickabrick)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function, called &amp;quot;clickabrick()&amp;quot;, has to be told what to do.  The function will print &amp;quot;Hi mom!&amp;quot;, but only if the function is called, namely, by clicking that specific brick.&lt;br /&gt;
&lt;br /&gt;
The last line is more complex now, but it has the same purpose as before -- calling the function.  On the left of the colon (:), you are describing the relation of where the triggering action (i.e., a MouseClick) is to the function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(Object).(Action):connect((Function Name))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
*[[Function Dump]]&lt;br /&gt;
*[[Functions in-depth]]&lt;br /&gt;
*[[In-Depth Scripting Guide]]&lt;/div&gt;</summary>
		<author><name>PRG</name></author>
	</entry>
</feed>