<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/wiki/Observable?action=history&amp;feed=atom</id>
	<title>Observable - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/wiki/Observable?action=history&amp;feed=atom"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=Observable&amp;action=history"/>
	<updated>2026-04-27T22:30: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=Observable&amp;diff=78819&amp;oldid=prev</id>
		<title>Limedev: Removed unnecessary padding.</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=Observable&amp;diff=78819&amp;oldid=prev"/>
		<updated>2024-02-14T12:56:18Z</updated>

		<summary type="html">&lt;p&gt;Removed unnecessary padding.&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 12:56, 14 February 2024&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-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&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;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;__NOTOC__&lt;/ins&gt;&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;{{Useful Class}}&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;{{Useful Class}}&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;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;__NOTOC__&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&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;This class allows you to watch for variables changes.&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 class allows you to watch for variables changes.&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;br/&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;br/&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key wiki-wiki_dev_:diff::1.12:old-67399:rev-78819 --&gt;
&lt;/table&gt;</summary>
		<author><name>Limedev</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=Observable&amp;diff=67399&amp;oldid=prev</id>
		<title>CrosRoad95: Created page with &quot;{{Useful Class}} __NOTOC__ This class allows you to watch for variables changes.  Call observable variable to push new state.  Author: CrosRoad95 Contact discord: mtasa.com/di...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=Observable&amp;diff=67399&amp;oldid=prev"/>
		<updated>2020-09-21T15:42:32Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{Useful Class}} __NOTOC__ This class allows you to watch for variables changes.  Call observable variable to push new state.  Author: CrosRoad95 Contact discord: mtasa.com/di...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Useful Class}}&lt;br /&gt;
__NOTOC__&lt;br /&gt;
This class allows you to watch for variables changes.&lt;br /&gt;
&lt;br /&gt;
Call observable variable to push new state.&lt;br /&gt;
&lt;br /&gt;
Author: CrosRoad95&lt;br /&gt;
Contact discord: mtasa.com/discord&lt;br /&gt;
==Requirements==&lt;br /&gt;
&lt;br /&gt;
OOP turn on&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
observable = {}&lt;br /&gt;
&lt;br /&gt;
function observable:onChange(callback)&lt;br /&gt;
	self.callback = callback&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function observable:__tostring()&lt;br /&gt;
	return self.value&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function observable:__call(newState)&lt;br /&gt;
	if(self.value == newState)then&lt;br /&gt;
		return false&lt;br /&gt;
	end&lt;br /&gt;
	local oldValue = self.value;&lt;br /&gt;
	self.value = newState;&lt;br /&gt;
	if(self.callback)then&lt;br /&gt;
		self.callback(oldValue, self.value)&lt;br /&gt;
	end&lt;br /&gt;
	return true;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function observable:create(defaultValue)&lt;br /&gt;
	local t = { value = defaultValue, observators = {} }&lt;br /&gt;
	setmetatable(t, self)&lt;br /&gt;
	self.__index = self&lt;br /&gt;
	return t&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function watch(callback, ...)&lt;br /&gt;
	for i,v in ipairs({...})do&lt;br /&gt;
		v:onChange(function(old, new) &lt;br /&gt;
			if(callback)then&lt;br /&gt;
				callback(i, old, new)&lt;br /&gt;
			end&lt;br /&gt;
		end)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Example 1==&lt;br /&gt;
How it works&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
a = observable:create(&amp;quot;asdf&amp;quot;) -- &amp;quot;asdf&amp;quot; is a default value.&lt;br /&gt;
b = observable:create(10)&lt;br /&gt;
&lt;br /&gt;
watch(function(index, prvValue, newValue) -- called every time observable value has change.&lt;br /&gt;
	print(&amp;quot;index&amp;quot;,index, &amp;quot;change&amp;quot;, prvValue, &amp;quot;=&amp;gt; &amp;quot;,newValue)&lt;br /&gt;
end, a, b) -- pass variables you want to watch&lt;br /&gt;
&lt;br /&gt;
a(20) -- index 1 change asdf =&amp;gt; 20&lt;br /&gt;
b(30) -- index 2 change 10 =&amp;gt; 30&lt;br /&gt;
a(&amp;quot;aaa&amp;quot;) -- index 1 change 20 =&amp;gt; aaa&lt;br /&gt;
&lt;br /&gt;
print(&amp;quot;value:&amp;quot;, a) -- in this case it will print &amp;quot;aaa&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Useful_Classes}}&lt;/div&gt;</summary>
		<author><name>CrosRoad95</name></author>
	</entry>
</feed>