<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.figuramc.org/index.php?action=history&amp;feed=atom&amp;title=Tutorials%2FPersisting-Variables</id>
	<title>Tutorials/Persisting-Variables - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.figuramc.org/index.php?action=history&amp;feed=atom&amp;title=Tutorials%2FPersisting-Variables"/>
	<link rel="alternate" type="text/html" href="https://wiki.figuramc.org/index.php?title=Tutorials/Persisting-Variables&amp;action=history"/>
	<updated>2026-04-28T15:44:12Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://wiki.figuramc.org/index.php?title=Tutorials/Persisting-Variables&amp;diff=847&amp;oldid=prev</id>
		<title>Riftlight: Fix init ping, and add clarifying comment regarding it</title>
		<link rel="alternate" type="text/html" href="https://wiki.figuramc.org/index.php?title=Tutorials/Persisting-Variables&amp;diff=847&amp;oldid=prev"/>
		<updated>2025-02-23T19:29:27Z</updated>

		<summary type="html">&lt;p&gt;Fix init ping, and add clarifying comment regarding it&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 19:29, 23 February 2025&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-l25&quot;&gt;Line 25:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 25:&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;end&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;end&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;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;pings.updateFromConfig(hatVisible, legLength, pantsColor)&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;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;function events.entity_init()&lt;/ins&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;&amp;lt;/syntaxhighlight&amp;gt;Finally, make some code that updates the config when you change values.&amp;lt;syntaxhighlight lang=&quot;lua&quot;&amp;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;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;    &lt;/ins&gt;pings.updateFromConfig(hatVisible, legLength, pantsColor)&lt;/div&gt;&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;end&lt;/ins&gt;&lt;/div&gt;&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;&amp;lt;/syntaxhighlight&amp;gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;You&#039;ll notice we call the ping in entity_init. Since this will not be called for people who only later load the avatar, you should also sync pings every so often in a tick event. &lt;/ins&gt;Finally, make some code that updates the config when you change values.&amp;lt;syntaxhighlight lang=&quot;lua&quot;&amp;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;-- The host:isHost() checks are not necessary, but they help explicitly show that their content is host-only&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;-- The host:isHost() checks are not necessary, but they help explicitly show that their content is host-only&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 pings.toggleHat(state)&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 pings.toggleHat(state)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key wiki:diff:1.41:old-830:rev-847:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Riftlight</name></author>
	</entry>
	<entry>
		<id>https://wiki.figuramc.org/index.php?title=Tutorials/Persisting-Variables&amp;diff=830&amp;oldid=prev</id>
		<title>Riftlight: Clarify host:isHost checks</title>
		<link rel="alternate" type="text/html" href="https://wiki.figuramc.org/index.php?title=Tutorials/Persisting-Variables&amp;diff=830&amp;oldid=prev"/>
		<updated>2025-01-07T01:13:43Z</updated>

		<summary type="html">&lt;p&gt;Clarify host:isHost checks&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 01:13, 7 January 2025&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-l27&quot;&gt;Line 27:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 27:&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;pings.updateFromConfig(hatVisible, legLength, pantsColor)&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;pings.updateFromConfig(hatVisible, legLength, pantsColor)&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&amp;gt;Finally, make some code that updates the config when you change values.&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&amp;gt;Finally, make some code that updates the config when you change values.&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;-- &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Check if &lt;/del&gt;host:isHost() &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;to ensure &lt;/del&gt;that &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;the config:save &lt;/del&gt;only &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;runs for the host&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;-- &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;The &lt;/ins&gt;host:isHost() &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;checks are not necessary, but they help explicitly show &lt;/ins&gt;that &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;their content is host-&lt;/ins&gt;only&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 pings.toggleHat(state)&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 pings.toggleHat(state)&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;     models.model.root.Head.Hat:setVisible(state)&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;     models.model.root.Head.Hat:setVisible(state)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key wiki:diff:1.41:old-385:rev-830:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Riftlight</name></author>
	</entry>
	<entry>
		<id>https://wiki.figuramc.org/index.php?title=Tutorials/Persisting-Variables&amp;diff=385&amp;oldid=prev</id>
		<title>Riftlight: Move from configapi</title>
		<link rel="alternate" type="text/html" href="https://wiki.figuramc.org/index.php?title=Tutorials/Persisting-Variables&amp;diff=385&amp;oldid=prev"/>
		<updated>2024-09-29T00:17:00Z</updated>

		<summary type="html">&lt;p&gt;Move from configapi&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Avatars can use the [[ConfigAPI]] to make their variables persist across reloads. This can be used for things such as saving settings across avatars or saving information about an avatar&amp;#039;s state. &lt;br /&gt;
&lt;br /&gt;
To begin with, create a config file. This can be done with either a script or a /figura run command; it&amp;#039;s safest to use a script in an IDE to have syntax highlighting and avoid errors. &amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
config:setName(&amp;quot;variablePersistence&amp;quot;)&lt;br /&gt;
-- All keys must be strings!&lt;br /&gt;
config:save(&amp;quot;pantsColor&amp;quot;, vec(0.5, 0.8, 0.1))&lt;br /&gt;
config:save(&amp;quot;hatVisible&amp;quot;, true)&lt;br /&gt;
config:save(&amp;quot;legLength&amp;quot;, 5)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;Run this script by selecting the avatar it&amp;#039;s under. Once it&amp;#039;s run, check the existence of the &amp;lt;code&amp;gt;variablePersistence.json&amp;lt;/code&amp;gt; file at &amp;lt;code&amp;gt;figura/config&amp;lt;/code&amp;gt;. If it&amp;#039;s there, that code can be deleted. Next, make some code to read the data in that file when the script is loaded. &amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
config:setName(&amp;quot;variablePersistence&amp;quot;)&lt;br /&gt;
-- The &amp;quot;or (value)&amp;quot; syntax sets the default value if the config:load is nil&lt;br /&gt;
local hatVisible = config:load(&amp;quot;hatVisible&amp;quot;) or true&lt;br /&gt;
local legLength = config:load(&amp;quot;legLength&amp;quot;) or 1&lt;br /&gt;
local pantsColor = config:load(&amp;quot;pantsColor&amp;quot;) or vec(0.9, 0.1, 0.9)&lt;br /&gt;
&lt;br /&gt;
function pings.updateFromConfig(hat, leg, pants)&lt;br /&gt;
    models.model.root.Head.Hat:setVisible(hat)&lt;br /&gt;
&lt;br /&gt;
    models.model.root.LeftLeg:setScale(1, leg, 1)&lt;br /&gt;
    models.model.root.RightLeg:setScale(1, leg, 1)&lt;br /&gt;
    &lt;br /&gt;
    models.model.root.LeftLeg[&amp;quot;Left Pants&amp;quot;]:setColor(pants)&lt;br /&gt;
    models.model.root.RightLeg[&amp;quot;Right Pants&amp;quot;]:setColor(pants)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
pings.updateFromConfig(hatVisible, legLength, pantsColor)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;Finally, make some code that updates the config when you change values.&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Check if host:isHost() to ensure that the config:save only runs for the host&lt;br /&gt;
function pings.toggleHat(state)&lt;br /&gt;
    models.model.root.Head.Hat:setVisible(state)&lt;br /&gt;
    if host:isHost() then&lt;br /&gt;
        config:save(&amp;quot;hatVisible&amp;quot;, state)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function pings.scaleLegs(scale)&lt;br /&gt;
    models.model.root.LeftLeg:setScale(1, scale, 1)&lt;br /&gt;
    models.model.root.RightLeg:setScale(1, scale, 1)&lt;br /&gt;
    if host:isHost() then&lt;br /&gt;
        config:save(&amp;quot;legLength&amp;quot;, scale)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function pings.colorPants(rgb)&lt;br /&gt;
    models.model.root.LeftLeg[&amp;quot;Left Pants&amp;quot;]:setColor(rgb)&lt;br /&gt;
    models.model.root.RightLeg[&amp;quot;Right Pants&amp;quot;]:setColor(rgb)&lt;br /&gt;
    if host:isHost() then&lt;br /&gt;
        config:save(&amp;quot;pantsColor&amp;quot;, rgb)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Riftlight</name></author>
	</entry>
</feed>