Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I use the Pages Object?

Asked by
Minifig77 190
10 years ago

Basically, using a server script, I want to get all of the enemies of a group. I found out that there was a way to do this: A game service called GroupService had a method called GetEnemiesAsync. I looked up the documentation for GetEnemiesAsync on the Wiki, and it said that it returned an object called Pages. However, the article didn't make it clear how I was to retrieve data from the Pages.

How do I get data from the Pages object?

1 answer

Log in to vote
0
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
10 years ago

In the case of the GetEnemiesAsync function, it will return a Pages instance which is essentially just an array of pages that have all the enemy groups of that particular group on it. To advance to the next page, you can use the the function AdvanceToNextPageAsync. Here is an example on how to check to see if a particular group is an enemy of another.

01function checkIfEnemy(group, enemyGroup)
02    local pages = game:GetService("GroupService"):GetEnemiesAsync(group)
03    local isEnemy = false
04    while true do
05        for _, group in pairs(pages:GetCurrentPage()) do
06            if group.Id == enemyGroup then
07                isEnemy = true
08            end
09        end
10        if pages.IsFinished then
11            break
12        end
13        pages:AdvanceToNextPageAsync()
14    end
15    return isEnemy
16end
17 
18print(checkIfEnemy(28, 131688)) -- Output : true
19print(checkIfEnemy(28, 100)) -- Output : false

The main thing to point out here is that a Pages object is an array of pages and each page has groups on it. Here is a example of what the layout of one of these groups would look like.

01local group = {
02    Name = "Knights of the Seventh Sanctum ";
03    Id = 377251;
04    Owner = {
05        Name = "Vilicus";
06        Id = 23415609;
07    };
09    Description = "We fight alongside the balance to make sure no one becomes to powerful. For guidance we look to the Earth as there is nothing more pure. ";
10    Roles = {
11        {
12            Name = "Apprentice";
13            Rank = 1;
14        }, {
15            Name = "Warrior";
View all 22 lines...

Knowing this you could rip apart the group piece by piece. Say you want the Description of the group, you'd simple use the line group.Description.

Ad

Answer this question