TableState
This class is used to observe and modify values in a TableManager easier. It is not feature complete and is subject to change.
Functions
new
Creates a new TableState. This is used to observe and modify values in a TableManager easier.
Equivalent to tblMngr:ToState(Path)
local tbl = {
Coins = 0;
Inventory = {
"Sword";
"Shield";
};
}
local tblMngr = TableManager.new(tbl)
local coinsState = TableState.new(tblMngr, "Coins")
print( coinsState == tblMngr:ToTableState("Coins") ) -- true
coinsState:Set(100) -- equivalent to `tblMngr:SetValue("Coins", 100)`
local inventoryState = TableState.new(tblMngr, "Inventory")
inventoryState:Insert("Potion") -- equivalent to `tblMngr:ArrayInsert("Inventory", "Potion")`
States with array values
You should avoid setting states to be a particular index in array because if the array is shifted then the state can potentially be pointing to the wrong value.
Set
TableState:
Set
(
...:
any
) →
(
)
Sets the value this state is associated with.
:Set(999) -- Sets the value itself to 999
:Set(1, 999) -- Sets the value at index 1 to 999 (State must be an array)
Get
TableState:
Get
(
index:
number?
) →
any
Gets the value this state is associated with. Takes an optional argument to specify the index of the array to get.
:Get() -- Gets the value itself
:Get(1) -- Gets the value at index 1 of the state (State must be an array) (Equivalent to :Get()[1])
Increment
TableState:
Increment
(
...:
any
) →
any
Increments the value this state is associated with.
:Increment(999) -- Increments the value itself by 999
:Increment(1, 999) -- Increments the value at index 1 by 999 (State must be an array)
Insert
TableState:
Insert
(
...:
any
) →
(
)
Inserts a value into the array this state is associated with.
:Insert(999) -- Appends 999 onto the array
:Insert(5, 999) -- Inserts 999 at index 5 of the array
Remove
TableState:
Remove
(
index:
number
) →
any
--
The removed value.
Removes the value at the given index from the array this state is associated with.
RemoveFirstValue
TableState:
RemoveFirstValue
(
valueToFind:
any
) →
number
--
The index of the removed value.
Removes the first value that matches the given value from the array this state is associated with.
Observe
TableState:
Observe
(
fn:
(
new:
any
)
→
(
)
) →
(
)
→
(
)
Observes changes to the value this state is associated with. Also fires immediately. See TableManager:Observe for more information.