FriendPages
*Ta zawartość została przetłumaczona przy użyciu narzędzi AI (w wersji beta) i może zawierać błędy. Aby wyświetlić tę stronę w języku angielskim, kliknij tutaj.
FriendPages to specjalna wersja Pages zwrócona przez Players:GetFriendsAsync(). Zawiera ona informacje o przyjaciół gracza i ma następującą strukturę:
<tr><td><code>Imię wyświetlanie</code></td><td>ciąg</td><td>Obecna nazwa wyświetlania znajomy.</td></tr><tr><td><code>Idź</code></td><td>int64</td><td>ID użytkownika znajomy.</td></tr><tr><td><code>Imię użytkownika</code></td><td>ciąg</td><td>Imię znajomy.</td></tr>
Nazwa | Typ | Opis |
Zobacz przykłady kodu, aby ziterować nad przyjaciółmi gracza.
Przykłady kodu
This code sample loads the Player.UserId of the player whose username is provided at the top of the script by using Players:GetUserIdFromNameAsync(). Then, it gets a FriendPages object by calling Players:GetFriendsAsync() and iterates over each entry using the iterPageItems function. The username of each friend is stored in a table, then printed at the end.
local Players = game:GetService("Players")
local USERNAME = "Cozecant"
local function iterPageItems(pages)
return coroutine.wrap(function()
local pagenum = 1
while true do
for _, item in ipairs(pages:GetCurrentPage()) do
coroutine.yield(item, pagenum)
end
if pages.IsFinished then
break
end
pages:AdvanceToNextPageAsync()
pagenum = pagenum + 1
end
end)
end
-- First, get the user ID of the player
local userId = Players:GetUserIdFromNameAsync(USERNAME)
-- Then, get a FriendPages object for their friends
local friendPages = Players:GetFriendsAsync(userId)
-- Iterate over the items in the pages. For FriendPages, these
-- are tables of information about the friend, including Username.
-- Collect each username in a table
local usernames = {}
for item, _pageNo in iterPageItems(friendPages) do
table.insert(usernames, item.Username)
end
print("Friends of " .. USERNAME .. ": " .. table.concat(usernames, ", "))
Podsumowanie
Metody
Metody odziedziczeni z: PagesRestituje pozycje na bieżącej stronie. Klucze w pozycji są określone przez źródło tego obiektu.
Przy pomocy innych właściwości strony można przejść do następnej strony w obiegu stron, jeśli to możliwe.