# How to dynamicaly display text from table (SOLVED)

**URL:** <https://forum.defold.com/t/how-to-dynamicaly-display-text-from-table-solved/69094>\
**Category:** Questions\
**Created:** [August 16, 2021, 8:24pm UTC](https://forum.defold.com/t/how-to-dynamicaly-display-text-from-table-solved/69094 "2021-08-16T20:24:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Troll](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/troll/32/25905_2.png) [@Troll](https://forum.defold.com/u/Troll)\
**Post date:** [August 16, 2021, 8:24pm UTC](https://forum.defold.com/t/how-to-dynamicaly-display-text-from-table-solved/69094/1 "2021-08-16T20:24:47Z")

</div>

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](https://forum.defold.com/t/create-multiple-object-slightly-different-solved/9995)  
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.

---

<div class="post-metadata">

**Author:** ![kiprono](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/kiprono/32/21981_2.png) [@kiprono](https://forum.defold.com/u/kiprono)\
**Post date:** [August 17, 2021, 10:49am UTC](https://forum.defold.com/t/how-to-dynamicaly-display-text-from-table-solved/69094/2 "2021-08-17T10:49:36Z")

</div>

Increment the y position. Like so

```lua
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.

---

<div class="post-metadata">

**Author:** ![Troll](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/troll/32/25905_2.png) [@Troll](https://forum.defold.com/u/Troll)\
**Post date:** [August 18, 2021, 3:57am UTC](https://forum.defold.com/t/how-to-dynamicaly-display-text-from-table-solved/69094/3 "2021-08-18T03:57:46Z")

</div>

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
