Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

ConfigAPI: Difference between revisions

From FiguraMC
PenguinEncounter (talk | contribs)
Create documentation
Tag: 2017 source edit
 
PenguinEncounter (talk | contribs)
m fix busted links
Tag: 2017 source edit
 
(8 intermediate revisions by 3 users not shown)
Line 5: Line 5:
ConfigAPI is available as the global <code>config</code> variable.
ConfigAPI is available as the global <code>config</code> variable.


== Data Types ==
== Data types ==
Only some data types are supported by ConfigAPI. All other data types will be converted to {{type|nil}}. The supported data types are:
Only some data types are supported by ConfigAPI. All other data types will be converted to {{type|nil}}. The supported data types are:
* {{type|nil}}
* {{type|nil}}
Line 14: Line 14:
* all types of {{type|Vector}}
* all types of {{type|Vector}}
* all types of {{type|Matrix}}
* all types of {{type|Matrix}}
<!-- add a tutorial! -->
== ConfigAPI methods ==
== ConfigAPI Methods ==


=== Configuration Switching ===
=== Configuration switching ===
 
==== <code>ConfigAPI:setName</code> ====


==== setName ====
----
Also available as <code>ConfigAPI:name</code>.
Also available as <code>ConfigAPI:name</code>.


Line 36: Line 35:
</syntaxhighlight>
</syntaxhighlight>


==== <code>ConfigAPI:getName</code> ====
==== getName ====
 
----
Returns the name of the active configuration file.
Returns the name of the active configuration file.


Line 52: Line 51:
</syntaxhighlight>
</syntaxhighlight>


=== Reading and Writing Data ===
=== Reading and writing data ===
==== <code>ConfigAPI:load</code> ====
==== load ====
 
----
Read a saved value from the active configuration file (see [[ConfigAPI#ConfigAPI:setName|setName]]) by key and return it.
Read a saved value from the active configuration file (see [[ConfigAPI#setName|setName]]) by key and return it.
If no key is given, return all of the saved keys and values in a table.
If no key is given, return all of the saved keys and values in a table.


Line 75: Line 74:
</syntaxhighlight>
</syntaxhighlight>


==== <code>ConfigAPI:save</code> ====
==== save ====
 
----
Associate a key with a value in the active configuration file (see [[ConfigAPI#ConfigAPI:setName|setName]].) Only some types of values are allowed; see [[ConfigAPI#Data Types|Data Types]] for details.
Associate a key with a value in the active configuration file (see [[ConfigAPI#setName|setName]].) Only some types of values are allowed; see [[ConfigAPI#Data Types|Data Types]] for details.


If {{type|nil}} is provided as the value, then the key is removed from the file.
If {{type|nil}} is provided as the value, then the key is removed from the file.
Line 92: Line 91:
config:save("my_value", "Figura Wiki")
config:save("my_value", "Figura Wiki")
</syntaxhighlight>
</syntaxhighlight>
== See also ==
* [[Tutorials/Persisting-Variables|Persisting Variables]] (tutorial)
== Navigation ==
{{Navbox documentation}}

Latest revision as of 22:39, 6 October 2024

This API is only available on the host.

For more information, see Pings.

The ConfigAPI allows storing and loading data between reloads of your avatar.

ConfigAPI is available as the global config variable.

Data types

Only some data types are supported by ConfigAPI. All other data types will be converted to nil. The supported data types are:

ConfigAPI methods

Configuration switching

setName


Also available as ConfigAPI:name.

Sets the name of the configuration file to read and write data to. By default, the name of the configuration file is the same as the name of the currently loaded avatar.

Arguments Return Type
setName(name string) self ConfigAPI
config:setName("my_config_file_name")

getName


Returns the name of the active configuration file.

Arguments Return Type
getName() string
-- Print the active configuration file's name.
print(config:getName())

Reading and writing data

load


Read a saved value from the active configuration file (see setName) by key and return it. If no key is given, return all of the saved keys and values in a table.

Arguments Return Type
load(key string) any | nil
load() table
-- Print all saved values.
printTable(config:load())
-- Print one specific value.
print(config:load("my_value"))

save


Associate a key with a value in the active configuration file (see setName.) Only some types of values are allowed; see Data Types for details.

If nil is provided as the value, then the key is removed from the file.

Arguments Return Type
save(key string, value any | nil) self ConfigAPI
-- Save a value to be used later.
config:save("my_value", "Figura Wiki")

See also

Navigation

Documentation
Globals
APIs (Types)
Visuals (Types)
Other Types
Enums