Skip to content

The For Objects

Import Weave.ForPairs, Weave.ForKeys, or Weave.ForValues from the Weave module.

1
2
3
4
local Weave = require(ReplicatedStorage.Weave)
local ForValues = Weave.ForValues
local ForKeys = Weave.ForKeys
local ForPairs = Weave.ForPairs

Weave has functions for turning Weave Value or Computed into an Instance

local playerNames = Value.new({ "Kreekcraft", "Sleitnick" })

ForValues(playerNames, function(name)
    return Attach(TextLabel:Clone()) {
        Text = name,
        Parent = screenGui
    }
end)

For function update state automatically

playerNames.set({ "Sleitnick" }) -- "Kreekcraft" TextLabel is Destroyed

For functions turn Weave state into UI.

Image title
Source: Pet Simulator 99. ForPairs turns state into UI.

Usage

For functions take

  1. A Weave Computed or Value table.

  2. A function that returns an Instance

local playerNames = Value.new({"Elttob", "boatbomber", "thisfall", "AxisAngles"})

ForValues(playerNames, someFunction)

Where someFunction

  • Receives a value from the table

  • Returns an Instance

ForValues(playerNames, function(name)
    local textLabel = TextLabel:Clone()

    return Attach(textLabel) {
        Text = playerName,
        Parent = ScreenGui
    }
end)

Over the next few pages, we'll take a look at three state objects:

  • ForValues: values in a table.
  • ForKeys: keys in a table.
  • ForPairs: keys and values in a table.