FriendPages
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
FriendPages เป็นรุ่นพิเศษของ Pages ที่กลับโดย Players:GetFriendsAsync() รายการภายในประกอบด้วยข้อมูลเกี่ยวกับเพื่อนของผู้เล่นและมีโครงสร้างด้านล่าง:
<tr><td><code>แสดงชื่อเรื่องการแสดงผล</code></td><td>สตริง</td><td>ชื่อแสดงผลปัจจุบันของเพื่อน</td></tr><tr><td><code>รหัส</code></td><td>int64</td><td>รหัสผู้ใช้ของเพื่อน</td></tr><tr><td><code>ชื่อผู้ใช้</code></td><td>สตริง</td><td>ชื่อผู้ใช้ของเพื่อน</td></tr>
ชื่อ | ชนิด | คำอธิบาย |
ดูตัวอย่างโค้ดสำหรับวิธีการทำซ้ำเพื่อนของผู้เล่น
ตัวอย่างโค้ด
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, ", "))
สรุป
วิธีการ
วิธีการรับทอดมาจากPagesส่งคืนรายการในหน้าปัจจุบัน รหัสในรายการถูกกำหนดโดยแหล่งของวัตถุนี้
ทำซ้ำไปยังหน้าต่อไปในวัตถุหน้า, ถ้าเป็นไปได้