This is for page systems such as those that use UIGridLayout
Ever needed to calculate how many pages you would need for a certain number of objects?
The Script
-- GetPages() Created by @FlaringSkies.
local function GetPages(Items, Debug)
--Template Pages: GetPages(Amount : number, DebugLogging : boolean)
local ItemNumber = tonumber(Items)
local CurrentNumber = ItemNumber
local SlotsPerPage = 4
local Pages = 0
if Debug == nil then
Debug = false
end
local function Log(Text, Type)
if Debug == true then
if Type == 1 then
print(Text)
end
if Type == 2 then
warn(Text)
end
end
end
if ItemNumber ~= nil then
if ItemNumber >= 0 then
while CurrentNumber > 0 do
if CurrentNumber - SlotsPerPage > 0 then
Pages += 1
CurrentNumber -= SlotsPerPage
else
CurrentNumber = 0
Pages += 1
break
end
end
local EmptySpaces = (SlotsPerPage*Pages)-ItemNumber
Log(("[#"..tostring(ItemNumber).."]: Objects need ".. Pages.. " pages and ".. EmptySpaces.. " empty spaces."), 1)
return Pages, EmptySpaces
else
Log(("[#"..tostring(ItemNumber).."]: Failed to get \"ItemNumber\" argument was less than 0."),2)
end
else
Log(("[#"..tostring(ItemNumber).."]: Failed to get \"ItemNumber\" argument returned nil."),2)
end
end
How do I use this?
Start off by changing the “SlotsPerPage
” variable to how many slots you have on each page, for me, I set it to 4 because there is only 4 slots on my page.
Next, if you want a simple return of how many pages and empty spaces you can use this:
local Pages, EmptySpaces = GetPages(AmountOfObjects: number, OPTIONAL: DebugPrinting : boolean)
-- Returns: number of pages, number of empty spaces
If you have any more questions about this feel free to ask!
Did you find this resourceful?
- Yes
- No
0 voters