<?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=Debounce</id>
	<title>Debounce - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.starfall.wtf/index.php?action=history&amp;feed=atom&amp;title=Debounce"/>
	<link rel="alternate" type="text/html" href="https://wiki.starfall.wtf/index.php?title=Debounce&amp;action=history"/>
	<updated>2026-07-28T17:09:08Z</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=Debounce&amp;diff=353&amp;oldid=prev</id>
		<title>PRG: Created page with &quot;&lt;!-- manually recreated, no source archive --&gt; {{CatUp|Tutorials}} __TOC__  == Introduction ==  A debounce system is a system that keeps a function from running too many times. It usually is used in a listener because a listener can be called many times while it&#039;s still working.   == The basic idea ==  &lt;pre&gt; enabled = true					--default is true, so that the function works function dosomething() 	if not enabled then return end		--if enabled is not true, then return withou...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.starfall.wtf/index.php?title=Debounce&amp;diff=353&amp;oldid=prev"/>
		<updated>2024-12-10T12:11:27Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;!-- manually recreated, no source archive --&amp;gt; {{CatUp|Tutorials}} __TOC__  == Introduction ==  A debounce system is a system that keeps a function from running too many times. It usually is used in a listener because a listener can be called many times while it&amp;#039;s still working.   == The basic idea ==  &amp;lt;pre&amp;gt; enabled = true					--default is true, so that the function works function dosomething() 	if not enabled then return end		--if enabled is not true, then return withou...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;!-- manually recreated, no source archive --&amp;gt;&lt;br /&gt;
{{CatUp|Tutorials}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
A debounce system is a system that keeps a function from running too many times. It usually is used in a listener because a listener can be called many times while it&amp;#039;s still working. &lt;br /&gt;
&lt;br /&gt;
== The basic idea ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
enabled = true					--default is true, so that the function works&lt;br /&gt;
function dosomething()&lt;br /&gt;
	if not enabled then return end		--if enabled is not true, then return without doing anything.&lt;br /&gt;
	enabled = false				--set enabled to false, because this function is already doing something.&lt;br /&gt;
	--stuff is done here			&lt;br /&gt;
	enabled = true				--open up the function to be called again.&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Debouncing works by setting the &amp;quot;gate&amp;quot; variable (in this case, enabled) to false while it is performing the stuff it needs to do so that it won&amp;#039;t get interrupted. After it is finished, it sets it back to true so that it can run again later. &lt;br /&gt;
&lt;br /&gt;
For example: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while true do&lt;br /&gt;
print(&amp;quot;Hello world1!&amp;quot;)     -- Prints Hello world1!&lt;br /&gt;
&lt;br /&gt;
enabled = true					--default is true, so that the function works&lt;br /&gt;
&lt;br /&gt;
function dosomething()&lt;br /&gt;
	if not enabled then return end		--if enabled is not true, then return without doing anything.&lt;br /&gt;
	enabled = false				--set enabled to false, because this function &lt;br /&gt;
                                                --is already doing something.&lt;br /&gt;
print(&amp;quot;Hello world2!&amp;quot;)&lt;br /&gt;
wait (5)&lt;br /&gt;
	enabled = true				--open up the function to be called again.&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
dosomething()  -- calls the dosomething function and prints Hello world2!&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Debounce in a real script ==&lt;br /&gt;
&lt;br /&gt;
Here&amp;#039;s the Local Gui script of the Rocket Launcher: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
enabled = true&lt;br /&gt;
function onButton1Down(mouse)&lt;br /&gt;
	if not enabled then&lt;br /&gt;
		return&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	enabled = false&lt;br /&gt;
	mouse.Icon = &amp;quot;rbxasset://textures\\GunWaitCursor.png&amp;quot;&lt;br /&gt;
&lt;br /&gt;
	wait(12)&lt;br /&gt;
	mouse.Icon = &amp;quot;rbxasset://textures\\GunCursor.png&amp;quot;&lt;br /&gt;
	enabled = true&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you fire a rocket, the script shows the reload icon. Then the function waits for 12 seconds. During this time, enabled is false, so if the player tries to fire another rocket, the script won&amp;#039;t run because the function will just return right away. After the 12 seconds are up, the reload cursor goes away and enabled becomes true again, allowing the user to fire another rocket. &lt;br /&gt;
&lt;br /&gt;
[[Category: Scripting Tutorials]]&lt;/div&gt;</summary>
		<author><name>PRG</name></author>
	</entry>
</feed>