Skip to content
Download

List of items (shop, inventory)

  1. In the Loja interface, add a Panel named Itens and, under Arrange children, pick Column.
  2. Inside it, build one item: a Panel Modelo with a Text Nome and a Button Comprar.
  3. Uncheck Visible on Modelo.
local itens = {
{ nome = "Espada", preco = 10 },
{ nome = "Escudo", preco = 40 },
}
function onSpawn(self)
local lista = Ui.get("Loja")["Itens"]
for n, item in ipairs(itens) do
local linha = lista["Modelo"]:clone("Item" .. n)
linha["Nome"]:setText(item.nome)
linha["Comprar"]:setText(item.preco .. " moedas")
linha["Comprar"]:onClick(self, function()
self.moedas = self.moedas - item.preco
linha["Comprar"]:setText("Comprado"):setEnabled(false)
end)
end
end
  • clone(name) copies Modelo with its contents, puts the copy at the end of the panel and makes it visible.
  • Calling clone with a name that already exists rebuilds the copy: restarting the room does not duplicate the list.
  • linha["Nome"] searches inside that copy. remove() removes a row, and the ones below move up.
  • List larger than the panel: check Scroll in the panel Inspector.
  • To keep purchases between sessions, use Save.

Reference: Interface.