ValuePath
A ValuePath is an array containing strings that Replicate uses to navigate Replicate objects.
Summary
Constructors
| ValuePath (path: strings | string) : ValuePath |
| fromKeyToPlainPath (pathKey: string) : strings |
| toPathKey (path: ValuePath) : string Deprecated |
Properties
| Optional : boolean |
Methods
| AsOptional () : ValuePath |
| __tostring () |
| __call () |
Constructors
ValuePath
ValuePath ( path: strings | string ) : ValuePath
Parameters
| path : strings | string |
Returns
| ValuePath |
fromKeyToPlainPath
Hidden
ValuePath.fromKeyToPlainPath ( pathKey: string ) : strings
Parameters
| pathKey : string |
Returns
| strings |
toPathKey
Deprecated
Hidden
ValuePath.toPathKey ( path: ValuePath ) : string
Parameters
| path : ValuePath |
Returns
| string |
Properties
Optional
Read Only
ValuePath.Optional ( ) : boolean
Methods
AsOptional
ValuePath:AsOptional ( ) : ValuePath
Returns
| ValuePath |
__tostring
Hidden
local path = ValuePath({ "fruit", "berries", "blueberries" })
tostring(path) --> "fruit\0berries\0blueberries"
__call
Hidden
local path = ValuePath({ "fruit", "berries", "blueberries" })
path() --> { "fruit", "berries", "blueberries" }
Examples
clientReplicate.Data = {
fruit = {
apple = true,
banana = false,
berries = {
strawberries = 10,
},
},
money = 100,
}
Tip
In code that frequently uses ValuePath objects, its faster and more performant to store the paths as a variable instead of calling ValuePath over and over.
local Replicate = require(path.to.Replicate)
local ValuePath = Replicate.Utility.ValuePath
local clientReplicate = Replicate.Client:GetReplicate()
while task.wait(10) do
-- This does work and wont create duplicate paths, however,
-- additional logic and checks are performed when ValuePath is called.
local money = clientReplicate:GetValue(ValuePath("money"))
...
end
Handling Optional Paths
If you attempt to call clientReplicate:GetValueChangedSignal() on a value that is nil, Replicate will output a warning. You can suppress this warning by telling Replicate that you expect this value to possibly be nil by accessing the path with :AsOptional() like:
local clientReplicate = ...
local path = ValuePath({ "fruit", "berries", "blueberries" })
-- this will send a warning based on our example data
clientReplicate:GetValueChangedSignal(path):Connect(...)
-- this will not send a warning even if blueberries is nil
clientReplicate:GetValueChangedSignal(path:AsOptional()):Connect(...)