<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/wiki/GUI_Classes/Button:AddOnTextChanged?action=history&amp;feed=atom</id>
	<title>GUI Classes/Button:AddOnTextChanged - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/wiki/GUI_Classes/Button:AddOnTextChanged?action=history&amp;feed=atom"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=GUI_Classes/Button:AddOnTextChanged&amp;action=history"/>
	<updated>2026-05-02T23:44:24Z</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=GUI_Classes/Button:AddOnTextChanged&amp;diff=44507&amp;oldid=prev</id>
		<title>Ccw: /* Example */</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=GUI_Classes/Button:AddOnTextChanged&amp;diff=44507&amp;oldid=prev"/>
		<updated>2015-02-11T16:35:16Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Example&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 16:35, 11 February 2015&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l24&quot;&gt;Line 24:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 24:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This example creates a button. The button has two functions attached to it, one is triggered when user clicks the button (to change text on the button) and the other one is triggered when the text has changed (which sets the text back to the old text).&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This example creates a button. The button has two functions attached to it, one is triggered when user clicks the button (to change text on the button) and the other one is triggered when the text has changed (which sets the text back to the old text).&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;addEventHandler ( &amp;quot;onClientResourceStart&amp;quot;, getResourceRootElement( &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;getThisResource( ) &lt;/del&gt;),&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;addEventHandler ( &amp;quot;onClientResourceStart&amp;quot;, getResourceRootElement(),&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     function( )&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     function( )&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;         --create a button object&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;         --create a button object&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key wiki-wiki_dev_:diff::1.12:old-18486:rev-44507 --&gt;
&lt;/table&gt;</summary>
		<author><name>Ccw</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=GUI_Classes/Button:AddOnTextChanged&amp;diff=18486&amp;oldid=prev</id>
		<title>50p: New page: &lt;pageclass class=&quot;client&quot; subcaption=&quot;GUI Class method&quot;&gt;&lt;/pageclass&gt; __NOTOC__   You can use this method to attach a function to a sham event which is triggered when text changes. The func...</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=GUI_Classes/Button:AddOnTextChanged&amp;diff=18486&amp;oldid=prev"/>
		<updated>2009-03-01T03:29:39Z</updated>

		<summary type="html">&lt;p&gt;New page: &amp;lt;pageclass class=&amp;quot;client&amp;quot; subcaption=&amp;quot;GUI Class method&amp;quot;&amp;gt;&amp;lt;/pageclass&amp;gt; __NOTOC__   You can use this method to attach a function to a sham event which is triggered when text changes. The func...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;pageclass class=&amp;quot;client&amp;quot; subcaption=&amp;quot;GUI Class method&amp;quot;&amp;gt;&amp;lt;/pageclass&amp;gt;&lt;br /&gt;
__NOTOC__ &lt;br /&gt;
&lt;br /&gt;
You can use this method to attach a function to a sham event which is triggered when text changes. The function you pass to this method will be triggered whenever button text changes (when [[GUI_Classes/GUISharedFuncs:Text|object:Text]] is used)&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
bool Button:AddOnTextChanged ( function func )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Required Arguments=== &lt;br /&gt;
*'''func:''' the function you want to add to a list of functions triggered when text changes&lt;br /&gt;
:&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;function func( buttonObject btn, string oldText, string newText )&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
:Parameters which are passed to this function&lt;br /&gt;
:*'''btn:''' button object which was created with [[GUI_Classes/Button:Create|Button:Create]] and the function was attached to&lt;br /&gt;
:*'''oldText''' string containing old text before the text was changed&lt;br /&gt;
:*'''newText''' string containing new text of the button&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
*'''true''' if function was added successfully &lt;br /&gt;
*'''false''' otherwise&lt;br /&gt;
&lt;br /&gt;
==Example== &lt;br /&gt;
This example creates a button. The button has two functions attached to it, one is triggered when user clicks the button (to change text on the button) and the other one is triggered when the text has changed (which sets the text back to the old text).&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
addEventHandler ( &amp;quot;onClientResourceStart&amp;quot;, getResourceRootElement( getThisResource( ) ),&lt;br /&gt;
    function( )&lt;br /&gt;
        --create a button object&lt;br /&gt;
        local button = Button:Create( 0.7, 0.1, 0.2, 0.1, &amp;quot;Hello&amp;quot;, true );&lt;br /&gt;
&lt;br /&gt;
        -- and attach a function to the button which changes its text&lt;br /&gt;
        button:AddOnClick( changeMyText );&lt;br /&gt;
&lt;br /&gt;
        -- add myTextHasChanged to the list of triggered functions when text changes&lt;br /&gt;
        button:AddOnTextChanged( myTextHasChanged );&lt;br /&gt;
    end&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
--setup a function to change the text&lt;br /&gt;
function changeMyText ( )&lt;br /&gt;
    local text = button:Text( ) --get the text from the button&lt;br /&gt;
    if text == &amp;quot;Hello&amp;quot; then&lt;br /&gt;
        -- if text of button was &amp;quot;Hello&amp;quot;, change it to &amp;quot;World!&amp;quot;&lt;br /&gt;
        button:Text( &amp;quot;World!&amp;quot; );&lt;br /&gt;
        button:Enabled( false );&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function myTextHasChanged( btn, oldText, newText  )&lt;br /&gt;
    -- if new text is &amp;quot;World!&amp;quot; then set a timer which will change it back to old text (in this case &amp;quot;Hello&amp;quot;)&lt;br /&gt;
    -- and enable the button&lt;br /&gt;
    if newText == &amp;quot;World!&amp;quot; then&lt;br /&gt;
        setTimer( btn:Text, 2500, 1, oldTex );&lt;br /&gt;
        setTimer( btn:Enabled, 2500, 1, true );&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
[[GUI_Classes|Back to GUI Classes page]]&lt;br /&gt;
{{GUI_Classes_allfunctions}}&lt;/div&gt;</summary>
		<author><name>50p</name></author>
	</entry>
</feed>