I literally have done this like 89 times before but I can’t figure it out right now. I’m trying to display the things in my table in pages in my UI element. I want to only show 4 things in the table per page.
The problem is, I can’t get the pages to start at the right spot in the table. If someone could just show an example to refresh my memory that would rock.
Integer divide the index.
i.e.
local numPerPage = 4
for index, value in next, tb do
local page = math.ceil(index/numPerPage)
-- do something here
end
4 Likes
I figured it out. Every time the user goes to the next page, I needed to add 4 to start
(variable for when the table begins.) Then to index the items in the table, I did this:
for i = 0, max-1 do --Subtract one from where you want to start and the maximum number, 4.
local item = tbl[start + i] --The item.
end
This is probably terribly explained but it worked. Maybe someone can explain what I’m doing better…
This looks 10x as better than whatever on Earth I came up with. Thanks.
1 Like