Module expcore.store
Adds an easy way to store and watch for updates to a value [[
Functions
Store.is_registered (location) | Check for if a lcoation is registered |
Store.uid_location () | Returns a unqiue name that can be used for a store |
Store.register (location, callback[, start_value]) | Registers a new location with an update callback which is triggered when the value updates |
Store.register_synced (location, callback[, start_value]) | Registers a new cross server synced location with an update callback, and external script is required for cross server |
Store.add_watch (location, callback) | Adds a function that will be checked every tick for a change in the returned value, when the value changes it will be saved in the store |
Store.get (location[, no_error=false]) | Gets the value stored at a location, this location must be registered |
Store.set (location, value) | Sets the value at a location, this location must be registered, if server synced it will emit the change to file |
Store.get_children (location) | Gets all non nil children at a location, children can be added and removed during runtime this is similar to Store.get but will always return a table even if it is empty |
Store.get_child (location, child) | Gets the value of the child to a location, children can be added and removed during runtime |
Store.set_child (location, child, value) | Sets the value of the chlid to a location, children can be added and removed during runtime when a child is set it will call the update handler of the parent allowing children be to added at runtime this may be used when a player joins the game and the child is the players name |
Functions
- Store.is_registered (location)
-
Check for if a lcoation is registered
Parameters:
- location string the location to test for
Returns:
-
boolean
true if registered
- Store.uid_location ()
-
Returns a unqiue name that can be used for a store
Returns:
-
string
a unqiue name
- Store.register (location, callback[, start_value])
-
Registers a new location with an update callback which is triggered when the value updates
Parameters:
- location string string a unique that points to the data, string used rather than token to allow migration
- callback function this callback will be called when the stored value is set to a new value
- start_value any this value will be the inital value that is stored at this location (optional)
- Store.register_synced (location, callback[, start_value])
-
Registers a new cross server synced location with an update callback, and external script is required for cross server
Parameters:
- location string string a unique that points to the data, string used rather than token to allow migration
- callback function this callback will be called when the stored value is set to a new value
- start_value any this value will be the inital value that is stored at this location (optional)
- Store.add_watch (location, callback)
-
Adds a function that will be checked every tick for a change in the returned value, when the value changes it will be saved in the store
Parameters:
- location string the location where the data will be saved and compeared to, must already be a registered location
- callback function this function will be called every tick to check for a change in value
- Store.get (location[, no_error=false])
-
Gets the value stored at a location, this location must be registered
Parameters:
- location string the location to get the data from
- no_error boolean when true no error is returned if the location is not registered (default false)
Returns:
-
any
the data which was stored at the location
- Store.set (location, value)
-
Sets the value at a location, this location must be registered, if server synced it will emit the change to file
Parameters:
- location string the location to set the data to
- value any the new value to set at the location, value may be reverted if there is a watch callback
Returns:
-
boolean
true if it was successful
- Store.get_children (location)
-
Gets all non nil children at a location, children can be added and removed during runtime
this is similar to Store.get but will always return a table even if it is empty
Parameters:
- location string the location to get the children of
Returns:
-
table
a table containg all the children and they values
- Store.get_child (location, child)
-
Gets the value of the child to a location, children can be added and removed during runtime
Parameters:
- location string the location of which the child is located
- child string the child element to get the value of
Returns:
-
any
the value which was stored at that location
- Store.set_child (location, child, value)
-
Sets the value of the chlid to a location, children can be added and removed during runtime
when a child is set it will call the update handler of the parent allowing children be to added at runtime
this may be used when a player joins the game and the child is the players name
Parameters:
- location string the location of which the child is located
- child string the child element to set the value of
- value any the value to set at this location
Returns:
-
boolean
true if it was successful