<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/wiki/Debounce?action=history&amp;feed=atom</id>
	<title>Debounce - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/wiki/Debounce?action=history&amp;feed=atom"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=Debounce&amp;action=history"/>
	<updated>2026-05-19T09:01:09Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=Debounce&amp;diff=77915&amp;oldid=prev</id>
		<title>CrosRoad95: Created page with &quot;{{Useful Function}} &lt;lowercasetitle&gt;&lt;/lowercasetitle&gt; __NOTOC__ This function  is removing unwanted input noise from buttons, switches or other user input. see: https://www.techtarget.com/whatis/definition/debouncing  ==Syntax== &lt;syntaxhighlight lang=&quot;lua&quot;&gt; void debounce( number timeout, function callback, ...arguments) &lt;/syntaxhighlight&gt;  ==Code== &lt;section name=&quot;Shared&quot; class=&quot;both&quot; show=&quot;true&quot;&gt; &lt;syntaxhighlight lang=&quot;lua&quot;&gt; local debounces = {}  function debounce(timeou...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=Debounce&amp;diff=77915&amp;oldid=prev"/>
		<updated>2023-10-06T16:09:34Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{Useful Function}} &amp;lt;lowercasetitle&amp;gt;&amp;lt;/lowercasetitle&amp;gt; __NOTOC__ This function  is removing unwanted input noise from buttons, switches or other user input. see: https://www.techtarget.com/whatis/definition/debouncing  ==Syntax== &amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt; void debounce( number timeout, function callback, ...arguments) &amp;lt;/syntaxhighlight&amp;gt;  ==Code== &amp;lt;section name=&amp;quot;Shared&amp;quot; class=&amp;quot;both&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt; &amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt; local debounces = {}  function debounce(timeou...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Useful Function}}&lt;br /&gt;
&amp;lt;lowercasetitle&amp;gt;&amp;lt;/lowercasetitle&amp;gt;&lt;br /&gt;
__NOTOC__&lt;br /&gt;
This function  is removing unwanted input noise from buttons, switches or other user input.&lt;br /&gt;
see: https://www.techtarget.com/whatis/definition/debouncing&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
void debounce( number timeout, function callback, ...arguments)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&amp;lt;section name=&amp;quot;Shared&amp;quot; class=&amp;quot;both&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local debounces = {}&lt;br /&gt;
&lt;br /&gt;
function debounce(timeout, callback, ...)&lt;br /&gt;
    local id = tostring(callback)&lt;br /&gt;
&lt;br /&gt;
    if(isTimer(debounces[id]))then&lt;br /&gt;
        killTimer(debounces[id])&lt;br /&gt;
        debounces[id] = nil;&lt;br /&gt;
    end&lt;br /&gt;
    debounces[id] = setTimer(function(...)&lt;br /&gt;
        callback(...) &lt;br /&gt;
        debounces[id] = nil;&lt;br /&gt;
    end, timeout, 1, ...)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Author:''' CrosRoad95&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
&amp;lt;section name=&amp;quot;Shared&amp;quot; class=&amp;quot;both&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p style=&amp;quot;color:black;&amp;quot;&amp;gt;This example will ignore first 9 calls and only last one get called within 500ms timeout&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function callback(i)&lt;br /&gt;
    print(i)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
for i=1,10 do&lt;br /&gt;
    debounce(500, callback, i);&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Result in console: 10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
&lt;br /&gt;
{{Useful_Functions}}&lt;/div&gt;</summary>
		<author><name>CrosRoad95</name></author>
	</entry>
</feed>