How to dynamicaly display text from table (SOLVED)

I having been playing around with Defold a bit. But still pretty new to most of it. I have been stuck on how to create dynamic items. I have been looking at this
dynamic example
as and an example of how to do it.

So far I was able modify some of the example code below.

       players = load_users()
       local y = 0 
	   local player_label = gui.get_node("removeuserpromptinput")
	   
	   for index, data in ipairs(players) do
	    print("Player:" .. index .. " " .. data)
	    self.buttons = {}
	    local nodes = gui.clone_tree(player_label)
	 	local x = #self.buttons % 10 
	 	local y = math.floor(#self.buttons / 10)

	 	gui.set_position(nodes[hash("removeuserpromptinput")], vmath.vector3(10 + x * 20, 10 + y * 10, 0))
	 	gui.set_text(nodes[hash("removeuserpromptinput")], data)

this works but it jumbles all the player names on top of each other. So the names are not readable. I assume this has to do with the placement of the vmath.vector3. But I am not really sure how this works well enough to get my desired result. I have tried changing the values with mixed results.

Something like below is what is desired

player1
player2
player3
player4

Ideally I would like the window to grow based on the amount of players. A window with 3 players would be smaller than a window with 5 players as and example. But I can try and figure out that later after I get the names to display correctly. I am going to continue to look at this but figured I post this to see if someone could point me in the right direction. Any insight is appreciated.

Increment the y position. Like so

local offsety = 30
local pos = vmath.vector3(0,0,0)

for i, data in ipairs(players) do
   pos.y = pos.y + offsety
   gui.set_position(node,  pos)
   gui.set_text(node, "Player" .. tostring(i))
end

For scrollable panels and such, there is druid library.

2 Likes

Ah thanks for the code example this is what I was looking for. It works the way I wanted it to. I have not played with libraries yet but thanks for the recommendation