Skip to main content
Represents a mutable property that stores a value and supports change listeners.

Fields

value

The current value of the property. You can both read and assign to this field.
local health = vm:getNumber("health")

if health then
  print(health.value) -- read
  health.value = 100  -- write
end

addListener

Registers a listener that is called whenever the property’s value changes.
local health = vm:getNumber("health")

if health then
  local function onHealthChanged(prop)
    print("New health:", prop.value)
  end

  health:addListener(onHealthChanged)

  health.value = 50 -- Triggers listener
end

removeListener

Removes a previously registered listener.
local health = vm:getNumber("health")

if health then
  local function onHealthChanged(prop)
    print("New health:", prop.value)
  end

  health:addListener(onHealthChanged)

  health.value = 50 -- Triggers listener

  health:removeListener(onHealthChanged)
end