How to use Pages?

What are Pages | Roblox Creator Documentation for?
Any practical sample, any video?

A page refers to a list that matches a value with its key, an example of this is OrderedDataStore with GetSortedAsync, in short, it is an instance that stores information.
It is not exactly, but it is like a “physical” table since Page can have a parent.

1 Like

Thanks, but I still don’t understand what it’s for in practical terms.
Could you show an example script?

Sure, it’s a “physical table” that roblox returns when you call it, in this case I’ll use GetSortedAsync

local DS = game:GetService("DataStoreService"):GetOrderedDataStore("Example") 

local pages = DS:GetSortedAsync(false, 100)
while wait() do
	for rank, data in pairs(pages:GetCurrentPage()) do
		print(data.key, data.value)
	end

	if pages.IsFinished then  break  end
	pages:AdvanceToNextPageAsync()
end

Page will have all the values and keys of the request, but separated into groups, as if it were a book that orders everything in pages.
image

GetCurrentPage returns the current page, by default it is 1, this will return the table that contains that page
image

if you print, the table will be this

local Page1 = {
	[1] = {
		key = "A",
		value = 1
	},
	[2] = {
		key = "B",
		value = 2
	},
	[3] = {
		key = "C",
		value = 3
	}
}

AdvanceToNextPageAsync will advance to the next one, in this case it would be number 2
image

local Page2 = {
    [1] = {
    	key = "D",
   		value = 4
    },
    [2] = {
    	key = "E",
    	value = 5
    },
    [3] = {
   		key = "F",
    	value = 8
   	}
}

and so with all of them, in short, Pages is like a book that contains a table that orders into groups.

3 Likes

Thanks, I understand that Pages creates tables divided into subgroups.
However, what would be a use case in a game, for example?

It’s used a lot for OrderedDataStore, but there are other functions that return page variants, like GetGamePlacesAsync that returns StandardPages.

1 Like