State
The State module is used to create reactive state objects that can be bound to UI components.
State.new(initialValue) -> State
Parameters
- initialValue
- Type:
any
- Required:
Yes
- Description: The initial value for the state. Cannot be
nil
.
- Type:
Returns
- State
- Type:
State
- Always:
Yes
- Description: A new
State
object initialized with the given value.
- Type:
Description
Creates a new state object.
lua
local state = Vuxel.State.new(0)
State:Set(newValue) -> void
Parameters
- newValue
- Type:
any
- Required:
Yes
- Description: The new value for the state. Cannot be
nil
.
- Type:
Returns
- void
- Type:
nil
- Always:
Yes
- Description: No return value; the state is updated internally.
- Type:
Description
Updates the state with a new value and triggers any listeners.
lua
state:Set(5) -- State value is now 5
State:Get() -> Value
Parameters
- None
Returns
- Value
- Type:
any
- Always:
Yes
- Description: The current value of the state.
- Type:
Description
Returns the current state value.
lua
print(state:Get()) -- Outputs: 5
State:BindTo(instance, property) -> void
Parameters
- instance
- Type:
Instance
- Required:
Yes
- Description: The Roblox instance to bind the state to.
- Type:
- property
- Type:
string
- Required:
Yes
- Description: The property of the instance to update based on state changes.
- Type:
Returns
- void
- Type:
nil
- Always:
Yes
- Description: No return value; binds the state to the specified instance property.
- Type:
Description
Binds a state to a UI property, updating the state when the property changes.
lua
state:BindTo(myTextLabel, "Text")