FriendPages
*Nội dung này được dịch bằng AI (Beta) và có thể có lỗi. Để xem trang này bằng tiếng Anh, hãy nhấp vào đây.
FriendPages là một phiên bản đặc biệt của Pages được trả lại bởi Players:GetFriendsAsync() . Các mục được bao gồm trong bao gồm thông tin về bạn bè của một người chơivà có cấu trúc như sau:
<tr><td><code>Tên hiển thị</code></td><td>chuỗi</td><td>Tên hiện tại của người bạn bè.</td></tr><tr><td><code>Id</code></td><td>int64</td><td>ID người dùng của bạn bè.</td></tr><tr><td><code>Tên người chơi</code></td><td>chuỗi</td><td>Tên người bạn bè.</td></tr>
Tên | Kiểu | Mô tả |
Xem mẫu mã nhập code để itereate qua bạn bè của một người chơi.
Mẫu mã
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, ", "))
Tóm Tắt
Phương Pháp
Phương Pháp kế thừa từ PagesTrở lại các mục đã được hiển thị trên trang hiện tại. Các chìa khóa trong mục được xác định bởi nguồn của mục này.
Lặp lại đến trang tiếp theo trong đối tượng trang, nếu có thể.