FriendPages
*Konten ini diterjemahkan menggunakan AI (Beta) dan mungkin mengandung kesalahan. Untuk melihat halaman ini dalam bahasa Inggris, klik di sini.
FriendPages adalah versi khusus dari Pages yang dikembalikan oleh Players:GetFriendsAsync() .Item yang terkandung di dalamnya berisi informasi tentang teman pemain dan memiliki struktur berikut:
<th>Jenis</th><th>Deskripsi</th></tr><tr><td><code>Nama Tampilan</code></td><td>string</td><td>Nama tampilan saat ini dari teman.</td></tr><tr><td><code>Id</code></td><td>int64</td><td>ID pengguna teman.</td></tr><tr><td><code>Nama pengguna</code></td><td>string</td><td>Nama pengguna teman.</td></tr>
Nama |
Lihat sampel kode untuk cara mengulangi teman pemain.
Contoh Kode
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, ", "))
Rangkuman
Properti
Properti diwarisi dari PagesApakah halaman saat ini adalah halaman terakhir yang tersedia atau tidak.
Metode
Metode diwarisi dari PagesKembalikan item di halaman saat ini. Kunci-kunci dalam item ditentukan oleh sumber objek ini.
Mengulang ke halaman berikutnya dalam objek halaman, jika memungkinkan.