I have 100 table object in a table and i want a page system, in first page it will print 10 table object then it will print next 10 table object when i change a page. How can i do that?
2 Likes
I won’t just give you the script - here are the steps you can try to do this. If you have any concerns, I’ll be happy to help you.
- define a variable called
page
. This will tell you what page you are on. - Whenever the player wants to go left or right, increase or decrease page by 1. Make sure to use
math.clamp(page, 1, 10)
on the value of page, otherwise it will go below 1 and above 10. - Create a function called
RenderValues
with an argument ofcurrentpage
- Inside the function, we’re going to use a for loop from page - 1* 10 (if this returns 0, set it to 1 use the math.clamp method we used earlier) all the way up to page * 10.
- Inside the for loop, print
table[i]
, where i is the index of the for loop. - Call
RenderValues
whenever they want to change the page! Use the:GetAttributeChangedSignal
orChanged
events, or any events that you think would fit.
Change the script as you like, this is just a framework. Let me know if you need any help.
how can i create a folder for pages like first 10 object will goes to folder1 next 10 object will goes to folder2 how can i do that?
Ok, so we can do something like this
local table = {}
local currentPage = 1
local clampedPage = math.clamp(currentPage, 1, 10)
local function getPage()
for page = clampedPage * 10 , (clampedPage * 10) - 10, 1 do
--show it
end
end
Also, please stop ignoring.
ok but what i need to do now?
…
I am not sure what you mean but is this what you want?
local function printPage(tableToPrint, pageNumber)
pageNumber = math.clamp(pageNumber, 1, 10) -- Stops page number being below 1 and above 10
local startIndex = (pageNumber - 1) * 10 + 1 -- Gets starting index of given page number.
for index = startIndex, startIndex + 9 do
print(tableToPrint[index])
end
end
1 Like
The solution you marked was what I said -_-
1 Like
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.