DataModel
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
ข้อมูลแบบข้อมูล (ซึ่งมักจะเรียกว่า game หลังจากตัวแปร global ที่ใช้เพื่อเข้าถึงมัน) คือรากของ Workspace ที่ประกอบด้วยบริกา
ตัวอย่างโค้ด
Demonstrates using game, the root instance of DataModel, to get services such as Workspace and Lighting.
local Workspace = game:GetService("Workspace")
local Lighting = game:GetService("Lighting")
-- Examples of modifying properties of these services
Workspace.Gravity = 20
Lighting.ClockTime = 4
สรุป
คุณสมบัติ
อธิบายรหัสผู้ใช้หรือกลุ่มที่เป็นเจ้าของสถานที่
อธิบาย Entity.CreatorType ของสถานที่ ว่าจะเป็นเจ้าของโดยผู้ใช้หรือกลุ่มหรือไม่
อธิบายรหัสของประสบการณ์ที่ตั้งอยู่บนเซิร์ฟเวอร์
ไม่สามารถใช้งานได้ อธิบายว่า Enum.Genre ของสถานที่ในเว็บไซต์ Roblox ตามที่กำหนดไว้
รหัสประจำตัวผู้เล่นที่ไม่ซ้ำใครสำหรับเซิร์ฟเวอร์เกมที่ดำเนินการ
อธิบายรหัสสถานที่ที่ดำเนินการบนเซิร์ฟเวอร์
อธิบายเวอร์ชันของสถานที่ที่เซิร์ฟเวอร์ทำงานบน
อธิบายรหัสเซิร์ฟเวอร์ส่วนตัวของเซิร์ฟเวอร์หากเซิร์ฟเวอร์เป็นเซิร์ฟเวอร์ส่วนตัวหรือเป็น reserved server
อธิบาย Class.Player.UserId|userId ของ Class.Player ที่เป็นเจ้าของเซิร์ฟเวอร์ส่วนตัวหากเซิร์ฟเวอร์เป็นส่วนตัว
การอ้างอิงถึงบริการ Workspace
วิธีการ
ผูกคุณสมบัติให้เรียกก่อนที่จะปิดเซิร์ฟเวอร์
กลับตารางที่มีข้อมูลพื้นฐานเกี่ยวกับงานที่ประมาณเวลา
กลับรายการ Instances ที่เกี่ยวข้องกับ URL เนื้อหาที่ให้
กลับ true หากลูกค้าได้โหลดเกมเป็นครั้งแรก
ตั้งค่า DataModel.PlaceId ของเกมตัวอย่างปัจจุบันให้เป็น placeId ที่ให้ไว้
ตั้งค่า DataModel.GameId ของเซิร์ฟเวอร์ตัวอย่างปัจจุบันให้เป็น universeId ที่กำหนด
กลับรายการบริการที่ระบุโดยชื่อผู้ให้บริการถ้ามันถูกสร้างแล้ว ข้อผิดพลาดสำหรับชื่อที่ไม่ถูกต้อง
ส่งคืนบริการด้วยชื่อคลาสที่ร้องขอ โดยสร้างมันขึ้นมาหากมันไม่มีอยู่
อีเวนต์
เปิดเมื่อผู้ใช้สั่งและเพิ่มหรือลดคุณภาพของกราฟิกโดยใช้ปุ่มลัด
เกิดขึ้นในเครื่องคอมพิวเตอร์เมื่อเกมจบการโหลดครั้งแรก
เกิดขึ้นเมื่อสถานที่ปัจจุบันถูกออก
เปิดใช้งานเมื่อสร้างบริการ
ไฟร์เมื่อบริการกำลังจะถูกลบออก
คุณสมบัติ
CreatorId
สมบัตินี้อธิบายรหัสของผู้ใช้หรือกลุ่มที่เป็นเจ้าของสถานที่ หากสมบัติ DataModel.CreatorType เป็น User จากนั้น
ตัวอย่างโค้ด
This code sample will print an output when the user that owns the game, or a member of the group that owns the game joins the server.
To run this script, place it inside a Script in ServerScriptService
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
if game.CreatorType == Enum.CreatorType.User then
if player.UserId == game.CreatorId then
print("The place owner has joined the game!")
end
elseif game.CreatorType == Enum.CreatorType.Group then
if player:IsInGroup(game.CreatorId) then
print("A member of the group that owns the place has joined the game!")
end
end
end)
CreatorType
คุณสมบัตินี้อธิบาย Entity.CreatorType ของสถานที่ว่ามีเป็นเจ้าของโดยผู้ใช้หรือกลุ่มหรือไม่
หาก Enum.CreatorType เป็น 'ผู้ใช้' แล้วสมบัติ DataModel.CreatorId จะอธิบาย Class.Player.UserId|userId ของบัญชีที่เป็นเจ้าของเกม หาก 1> สร้างเกียรต
ตัวอย่างโค้ด
This code sample will print an output when the user that owns the game, or a member of the group that owns the game joins the server.
To run this script, place it inside a Script in ServerScriptService
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
if game.CreatorType == Enum.CreatorType.User then
if player.UserId == game.CreatorId then
print("The place owner has joined the game!")
end
elseif game.CreatorType == Enum.CreatorType.Group then
if player:IsInGroup(game.CreatorId) then
print("A member of the group that owns the place has joined the game!")
end
end
end)
GameId
รายการนี้อธิบายรหัสของประสบการณ์ที่ตั้งอยู่บนเซิร์ฟเวอร์
รหัสนี้สามารถพบได้ในมุมมองด้านขวาบนของ เมนเจอร์สินทรัพย์ ใน Roblox Studio เมื่อใช้ Roblox Studio หากสถานที่ยังไม่ได้เผยแพร่ไปยัง Roblox ก็จะมี GameId ตรงกับรูปแบบที่ใช้
ดูเพิ่มเติม:
- DataModel.PlaceId ซึ่งอธิบายรหัสสถานที่ที่ดำเนินการบนเซิร์ฟเวอร์
- DataModel.JobId ซึ่งเป็นรหัสอันเฉพาะสำหรับเซิร์ฟเวอร์เกมอินสแตนซ์ที่ดำเนินงาน
- TeleportService ซึ่งเป็นบริการที่สามารถใช้ได้เพื่อขนส่ง Players ระหว่างเกม
Genre
คุณสมบัตินี้พังและไม่ควรใช้
สถานที่นี้มีอยู่ในอดีตเคยอธิบาย Enum.Genre ของสถานที่นี้ในเว็บไซต์ Roblox ว่าอยู่ในตำแหน่งที่กำหนดไว้
คุณสมบัตินี้, พร้อมกับ DataModel.GearGenreSetting , ไม่สามารถทำงานได้อีกต่อไปเนื่องจากสไตล์ที่มีอยู่ในเว็บไซต์ Roblox ที่ไม่ได้รวมอยู่ใน Enum.Genre คลาสเรียบ
JobId
อินสแตนซ์มันเป็นรหัสที่ไม่มีใครเหมือน (ไม่มีที่อยู่ในตัวอักษร) ซึ่งหมายความว่าไม่มีเซิร์ฟเวอร์สองเครื่องที่ผ่านมาหรือปัจจุบันจะมีรหัสเดียวกั
ค่าเริ่มต้นสำหรับสตริงที่ว่างใน Studio
ดูเพิ่มเติม
- TeleportService:GetPlayerPlaceInstanceAsync() ซึ่งสามารถใช้เพื่อดึงข้อมูล DataModel.JobId ของเซิร์ฟเวอร์ปัจจุบันของผู้ใช้
- TeleportService:TeleportToPlaceInstance() ซึ่งสามารถใช้เพื่อเทเลพอร์ต Player ไปยังเซิร์ฟเวอร์ที่กำหนดเฉพาะ
- DataModel.PrivateServerId อธิบาย ID ของเซิร์ฟเวอร์ส่วนตัวที่เกมส์เซิร์ฟเวอร์อินสแตนซ์เป็นเจ้าของ
- HttpService:GenerateGUID() ระบบที่สามารถใช้เพื่อสร้าง UUID ของคุณเอง
PlaceId
คุณสมบัตินี้อธิบาย ID ของสถานที่ที่ดำเนินการบนเซิร์ฟเวอร์
หากสถานที่ถูกเผยแพร่ไปยัง Roblox ให้พบได้ที่ เมนูทรัพยากร โดยการคลิกขวาที่สถานที่ภายในโฟลเดอร์ สถานที่ และเลือก เคลื่อนย้าย ID ไปยังลายละคร
หากสถานที่ยังไม่ได้เผยแพร่ไปยัง Roblox รหัสนี้จะตรงกับรูปแบบที่ใช้
ดูเพิ่มเติม
- DataModel.GameId ซึ่งอธิบายรหัสของประสบการณ์ที่ตั้งอยู่ในปัจจุบัน
- DataModel.JobId ซึ่งเป็นรหัสอันเฉพาะสำหรับเซิร์ฟเวอร์เกมอินสแตนซ์ที่ดำเนินงาน
- TeleportService ซึ่งเป็นบริการที่สามารถใช้เพื่อขนส่ง Players ระหว่างสถานที่
PlaceVersion
คุณสมบัตินี้อธิบายเวอร์ชันของสถานที่ที่เซิร์ฟเวอร์กำลังประมวลผล
เวอร์ชันนี้ตรงกับเวอร์ชันนี้ที่ปรากฏใต้ส่วน ประวัติเวอร์ชัน ของการตั้งค่าสถานที่ มันไม่ใช่เวอร์ชันปัจจุบันของ Roblox ตัวนี้ มีค่า 0 สำหรับทุกประสบการณ์ที่ไม่เผยแพร่
เมื่อสร้างตัวอักษรเซิร์ฟเวอร์สำหรับสถานที่ มันจะใช้เวอร์ชันปัจจุบันของสถานที่ หากสถานที่ถูกปรับปรุงในภายหลังในขณะที่เซิร์ฟเวอร์นี้กำลังทำงาน เซิร์ฟเวอร์จะยังคงอยู่ในเวอร์ชันปัจจุบัน
สมบัตินี้สามารถใช้เพื่อแสดง ScreenGui ที่แสดงรุ่นปัจจุบันของเกมให้กับ Players เพื่อช่วยให้การดีบั๊ก
ตัวอย่างโค้ด
This code sample will place a simple GUI in the StarterGui showing the place version the server is running at.
To use this sample, place it inside a Script in ServerScriptService.
local StarterGui = game:GetService("StarterGui")
local versionGui = Instance.new("ScreenGui")
local textLabel = Instance.new("TextLabel")
textLabel.Position = UDim2.new(1, -10, 1, 0)
textLabel.AnchorPoint = Vector2.new(1, 1)
textLabel.Size = UDim2.new(0, 150, 0, 40)
textLabel.BackgroundTransparency = 1
textLabel.TextColor3 = Color3.new(1, 1, 1)
textLabel.TextStrokeTransparency = 0
textLabel.TextXAlignment = Enum.TextXAlignment.Right
textLabel.TextScaled = true
local placeVersion = game.PlaceVersion
textLabel.Text = string.format("Server version: %s", placeVersion)
textLabel.Parent = versionGui
versionGui.Parent = StarterGui
PrivateServerId
รายการนี้อธิบายรหัสเซิร์ฟเวอร์ส่วนตัวของเซิร์ฟเวอร์หากเซิร์ฟเวอร์เป็นเซิร์ฟเวอร์ส่วนตัว
หากเซิร์ฟเวอร์ไม่ใช่เซิร์ฟเวอร์ส่วนตัว, ค่านี้จะเป็นสตริงว่าง
เซิร์ฟเวอร์ส่วนตัว
กำลังติดตาม:
- เซิร์ฟเวอร์ส่วนตัว ที่ผู้ใช้สามารถซื้อได้จากหน้าเกม
- เซิร์ฟเวอร์สำรองที่สร้างขึ้นโดยผู้พัฒนาโดยใช้ TeleportService:ReserveServer()
PrivateServerId vs รหัสงาน
PrivateServerId ของเซิร์ฟเวอร์แตกต่างจาก DataModel.JobId ส่วน JobId อินสแตนซ์
เซิร์ฟเวอร์ส่วนตัว (เกม) สามารถมีหลายตัวอย่างเซิร์ฟเวอร์ที่เกี่ยวข้องกับพวกเขาในเวลาต่อมา
ดูเพิ่มเติม:
- DataModel.PrivateServerOwnerId คือค่าสมบัติที่อธิบายเจ้าของเซิร์ฟเวอร์ส่วนตัว
- TeleportService:ReserveServer() ระบบที่สร้างเซิร์ฟเวอร์สำรอง
ตัวอย่างโค้ด
DataModel.PrivateServerId and DataModel.PrivateServerOwnerId can be used to detect if the current server instance is a standard server, a VIP server or a reserved server.
local function getServerType()
if game.PrivateServerId ~= "" then
if game.PrivateServerOwnerId ~= 0 then
return "VIPServer"
else
return "ReservedServer"
end
else
return "StandardServer"
end
end
print(getServerType())
PrivateServerOwnerId
สมบัตินี้อธิบาย Class.Player.UserId|userId ของ Class.Player ที่เป็นเจ้าของ Class.Player ซึ่งเป็นเซิร์ฟเวอร์ส่วนตัวหากเซิร์ฟเวอร์เป็นส่วนตัว
หากเซิร์ฟเวอร์เป็นเซิร์ฟเวอร์สาธารณะหรือสำรองนี้จะได้รับการตั้งค่า 0
คุณสมบัตินี้สามารถใช้เพื่อระบุว่า Player เป็นเจ้าของเซิร์ฟเวอร์ส่วนตัวหรือไม่ โดยตัวอย่างเช่น:
local Players = game:GetService("Players")
-- นี่เป็นเซิร์ฟเวอร์ส่วนตัวหรือไม่?
if game.PrivateServerId ~= "" and game.PrivateServerOwnerId ~= 0 then
-- ฟังผู้เล่นใหม่ที่เพิ่มเข้ามา
Players.PlayerAdded:Connect(function(player)
-- ตรวจสอบว่าผู้เล่นเป็นเจ้าของเซิร์ฟเวอร์หรือไม่
if player.UserId == game.PrivateServerOwnerId then
print("The private server owner has joined the game")
end
end)
end
ดูเพิ่มเติม:
- DataModel.PrivateServerId คือคุณสมบัติที่อธิบายรหัสเฉพาะของเซิร์ฟเวอร์ส่วนตัวและ reserved servers
ตัวอย่างโค้ด
DataModel.PrivateServerId and DataModel.PrivateServerOwnerId can be used to detect if the current server instance is a standard server, a VIP server or a reserved server.
local function getServerType()
if game.PrivateServerId ~= "" then
if game.PrivateServerOwnerId ~= 0 then
return "VIPServer"
else
return "ReservedServer"
end
else
return "StandardServer"
end
end
print(getServerType())
Workspace
คุณสมบัติ Workspace เป็นการอ้างถึงบริการ Workspace
สมบัตินี้จะชี้ไปที่ Workspace และจะไม่เคยเป็น ไม่มี
Class.Workspace สามารถเข้าถึงได้โดยการใช้แปร global workspace และคุณสมบัติ ServiceProvider:GetService() ตัวอย่างเช่น:
workspace -- ตัวแปร globalgame.Workspace -- สมบัติของ DataModel (เกม)game:GetService("Workspace") -- workspace is a service
วิธีการ
BindToClose
ผูกคุณสมบัติให้เรียกก่อนที่เซิร์ฟเวอร์จะปิดลง หากคุณสมบัติผูกยอมรับตัวอักษร Enum.CloseReason จะส่งผ่าน EntityCloseReason เพื่อระบุเหตุผลในการปิดเซิร์ฟเวอร์
คุณสามารถผูกหลายหน้าโดยการเรียก BindToClose() ซ้ำแล้วซ้ำซาก. หน้าเชื่อมต่อจะเรียกในพาร์เลลและประมวลผลในเวลาเดียวกัน
เซิร์ฟเวอร์ประสบการณ์รอ 30 วินาทีสำหรับการทำงานทั้งหมดของตัวผู้ใช้จะหยุดทำงานก่อนที่จะปิดเซิร์ฟเวอร์ หลังจาก 30 วินาทีเซิร์ฟเวอร์จะปิดทำงานแม้ว่าการทำงานจะยังคงดำเนินการได้
เพื่อยืนยันว่าเซสชันปัจจุบันไม่ได้อยู่ใน Roblox Studio ใช้ RunService:IsStudio() นี้จะป้องกันให้ฟังก์ชันติดตัวจากการทำงานในเซสชันออฟไลน์
เมื่อคุณใช้ DataStoreService คุณควรใช้ BindToClose เพื่อผูกตัวเรื่องที่บันทึกทั้งหมดไปยัง DataStores เพื่อป้องกันการสูญเสียข้อมูลหากเซิร์ฟเวอร์ปิดการใช้
ดูเพิ่มเติม:
- Enum.CloseReason สําหรับเหตุผลในการปิดเซิร์ฟเวอร์ประสบการณ์
- PluginGui:BindToClose() ซึ่งผูกคุณสมบัติให้กับปุ่มปิด PluginGui
พารามิเตอร์
ฟังก์ชันที่เรียกก่อนที่เซิร์ฟเวอร์ปิดลง หากตัวแปรที่ผูกรับรองได้ยอมรับพารามิเตอร์ มันผ่าน Enum.CloseReason เพื่อระบุเหตุผลสำหรับการปิดเซิร์ฟเวอร์
ส่งค่ากลับ
ตัวอย่างโค้ด
The following code sample is an example of how DataModel:BindToClose() can be used to save player data in the event of a server shutdown. In this example, player data is stored in a dictionary named playerData with UserIds as keys.
local DataStoreService = game:GetService("DataStoreService")
local RunService = game:GetService("RunService")
local playerDataStore = DataStoreService:GetDataStore("PlayerData")
local allPlayerSessionDataCache = {}
local function savePlayerDataAsync(userId, data)
return playerDataStore:UpdateAsync(userId, function(oldData)
return data
end)
end
local function onServerShutdown(closeReason)
if RunService:IsStudio() then
-- Avoid writing studio data to production and stalling test session closing
return
end
-- Reference for yielding and resuming later
local mainThread = coroutine.running()
-- Counts up for each new thread, down when the thread finishes. When 0 is reached,
-- the individual thread knows it's the last thread to finish and should resume the main thread
local numThreadsRunning = 0
-- Calling this function later starts on a new thread because of coroutine.wrap
local startSaveThread = coroutine.wrap(function(userId, sessionData)
-- Perform the save operation
local success, result = pcall(savePlayerDataAsync, userId, sessionData)
if not success then
-- Could implement a retry
warn(string.format("Failed to save %d's data: %s", userId, result))
end
-- Thread finished, decrement counter
numThreadsRunning -= 1
if numThreadsRunning == 0 then
-- This was the last thread to finish, resume main thread
coroutine.resume(mainThread)
end
end)
-- This assumes playerData gets cleared from the data table during a final save on PlayerRemoving,
-- so this is iterating over all the data of players still in the game that hasn't been saved
for userId, sessionData in pairs(allPlayerSessionDataCache) do
numThreadsRunning += 1
-- This loop finishes running and counting numThreadsRunning before any of
-- the save threads start because coroutine.wrap has built-in deferral on start
startSaveThread(userId, sessionData)
end
if numThreadsRunning > 0 then
-- Stall shutdown until save threads finish. Resumed by the last save thread when it finishes
coroutine.yield()
end
end
game:BindToClose(onServerShutdown)
The following example prints the close reason to the output. It prints Done after three seconds, and then allows Roblox to shut down the experience server.
The close reason matches one of the values in Enum.CloseReason.
game:BindToClose(function(closeReason)
print(`Closing with reason {closeReason}`)
task.wait(3)
print("Done")
end)
GetJobsInfo
กลับตารางที่มีข้อมูลพื้นฐานเกี่ยวกับงานที่ประมาณเวลา
ในการคำนวณ ตัวจัดการภารกิจเป็นระบบที่รับผิดชอบในการประมาณเวลาการประมวลผลและการประมวลผลแบบขั้นสูง
คุณยังสามารถหาสถิติตัวจัดการงานสดในหน้าตัวจัดการงานใน Roblox Studio ได้
รายการแรกในตารางที่กลับมาคือคู่มืออ้างอิงที่มีสถิติ (หรือหัวข้อ) ที่มีอยู่ มันอยู่ในรูปแบบต่อไปนี้:
{["name"] = "name",["averageDutyCycle"] = "averageDutyCycle",["averageStepsPerSecond"] = "averageStepsPerSecond",["averageStepTime"] = "averageStepTime",["averageError"] = "averageError",["isRunning"] = "isRunning",}
รายการที่ปรากฏในตารางต่อไปนี้เป็นพจนานุกรมที่มีสถิติด้านบนสำหรับงานที่ดำเนินการโดยตัวประมวลผลงาน ตัวอย่างเช่น:
{["name"] = "Heartbeat",["averageDutyCycle"] = 0,["averageStepsPerSecond"] = 0,["averageStepTime"] = 0,["averageError"] = 0,["isRunning"] = false,}
ดูเพิ่มเติม:
ส่งค่ากลับ
ตารางที่มีข้อมูลเกี่ยวกับงานที่ประสานงานตรงไปยังตัวประมวลผล ดูด้านบนสำหรับรูปแบบ
ตัวอย่างโค้ด
Here is an example of iterating over the job info.
local jobInfo = game:GetJobsInfo()
local jobTitles = jobInfo[1]
table.remove(jobInfo, 1)
local divider = string.rep("-", 120)
print(divider)
warn("JOB INFO:")
print(divider)
for _, job in pairs(jobInfo) do
for jobIndex, jobValue in pairs(job) do
local jobTitle = jobTitles[jobIndex]
warn(jobTitle, "=", jobValue)
end
print(divider)
end
GetObjects
วิธีนี้กลับรายการ Instances ที่เกี่ยวข้องกับ URL เนื้อหาที่ให้ สามารถใช้เพื่อใส่เนื้อหาจากห้องสมุด Roblox ได้ ไม่สามารถใส่เนื้อหา Class.Sound
ในขณะที่ InsertService:LoadAsset() ไม่ต้องการให้มีสินทรัพย์เป็น "สินทรัพย์ที่ไว้วางใจ" Roblox
เนื่องจากสถานที่รักษาความปลอดภัยของฟังก์ชันนี้ มันสามารถใช้ได้เฉพาะโดยปลั๊กอินหรือแถบคําสั่ง สําหรับตัวเลือกที่สามารถใช้ใน Scripts และ
พารามิเตอร์
ที่อยู่ URL เนื้อหาที่ให้
ส่งค่ากลับ
Class.Instance|Instances รายการที่เกี่ยวข้องกับ URL เนื้อหา
ตัวอย่างโค้ด
If you want to view a plugin's source code without installing it, you can use DataModel:GetObjects() to download the plugin. The code sample below includes a function that will take a plugin's website URL and insert the plugin into the currently selected Instance or the Workspace.
Due to GetObjects' security context, this function can only be used in the command line or in a plugin.
local Selection = game:GetService("Selection")
local WEB_URL = "plugin URL here"
local function downloadPlugin(webURL)
-- get the content URL
local contentID = string.match(webURL, "%d+")
local contentURL = "rbxassetid://" .. contentID
-- download the objects
local objects = game:GetObjects(contentURL)
-- decide where to parent them
local selection = Selection:Get()
local parent = #selection == 1 and selection[1] or workspace
-- parent the objects
for _, object in pairs(objects) do
object.Parent = parent
end
end
downloadPlugin(WEB_URL)
The content ID of a Decal on the Roblox website is associated with a Decal Instance rather than the actual content ID of the texture.
The code below, will use DataModel:GetObjects() to insert Decal objects into place and read their Decal.Texture property to obtain the image content IDs.
To use this code sample, enter the web URLs of the decals you'd like to convert into the array named IMAGES (as strings). A dictionary with the converted textures will be outputted.
local IMAGES = {
-- Insert Decal web URLs in an array here (as strings)
}
-- open the dictionary
local outputString = "textures = {"
-- utility function to add a new entry to the dictionary (as a string)
local function addEntryToDictionary(original, new)
outputString = outputString
.. "\n" -- new line
.. " " -- indent
.. '["'
.. original
.. '"]' -- key
.. ' = "'
.. new
.. '",' -- value
end
print("Starting conversion")
for _, webURL in pairs(IMAGES) do
-- get the content URL
local contentID = string.match(webURL, "%d+")
local contentURL = "rbxassetid://" .. contentID
local success, result = pcall(function()
local objects = game:GetObjects(contentURL)
return objects[1].Texture
end)
if success then
addEntryToDictionary(webURL, result)
else
addEntryToDictionary(webURL, "Error downloading decal")
end
task.wait()
end
print("Conversion complete")
-- close the dictionary
outputString = outputString .. "\n}"
-- print the dictionary
print(outputString)
IsLoaded
ฟังก์ชันนี้จะกลับ true หากลูกค้าได้โหลดเกมเป็นครั้งแรก
เมื่อทุกอย่างเริ่มต้น Instances ในเกมเสร็จสิ้นแล้วจะส่งคืนค่า true
ยกเว้นพวกเขาจะเป็นลูกของ ReplicatedFirst , LocalScripts จะไม่รันเมื่อเกมยังไม่โหลด ส่วนตัวอย่างต่อไปนี้วิ่งจาก LocalScript ใน 1> Class.ReplicatedFirst
if not game:IsLoaded() thengame.Loaded:Wait()end
ดูเพิ่มเติม:
- DataModel.Loaded เหตุการณ์ที่เกิดขึ้นเมื่อเกมโหลดเสร็จ
- Instance:WaitForChild() ระบบที่สามารถใช้เพื่อรอให้ Instance ตัวนั้นเองเพื่อวิดีโอเกมทั้งหมด
ส่งค่ากลับ
ว่าลูกค้าจบการโหลดเกมครั้งแรกหรือไม่
ตัวอย่างโค้ด
This sample demonstrates a custom loading screen with a basic TextLabel. The code should be placed in a LocalScript within ReplicatedFirst. To expand on this sample with loading screen animations, see the Custom Loading Screens article.
local Players = game:GetService("Players")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
-- Create a basic loading screen
local screenGui = Instance.new("ScreenGui")
screenGui.IgnoreGuiInset = true
local textLabel = Instance.new("TextLabel")
textLabel.Size = UDim2.new(1, 0, 1, 0)
textLabel.BackgroundColor3 = Color3.fromRGB(0, 20, 40)
textLabel.Font = Enum.Font.GothamMedium
textLabel.TextColor3 = Color3.new(0.8, 0.8, 0.8)
textLabel.Text = "Loading"
textLabel.TextSize = 28
textLabel.Parent = screenGui
-- Parent entire screen GUI to player GUI
screenGui.Parent = playerGui
-- Remove the default loading screen
ReplicatedFirst:RemoveDefaultLoadingScreen()
--wait(3) -- Optionally force screen to appear for a minimum number of seconds
if not game:IsLoaded() then
game.Loaded:Wait()
end
screenGui:Destroy()
SetPlaceId
ฟังก์ชันนี้ตั้งค่า DataModel.PlaceId ของเกมไอน์สแตนซ์ไปยัง placeId ที่กำหนด
ต้องการการตั้งค่าทั้งสอง DataModel.PlaceId และ DataModel.GameId เพื่อเข้าถึง
local DataStoreService = game:GetService("DataStoreService")-- เข้าถึง DataStore 'Data' โดยการตั้งค่า PlaceId เป็น placeId และ GameId เป็น universeIdgame:SetPlaceId(placeId)game:SetUniverseId(universeId)local dataStore = DataStoreService:GetDataStore("Data")
พารามิเตอร์
รหัสที่ต้องการตั้ง DataModel.PlaceId
ส่งค่ากลับ
SetUniverseId
ฟังก์ชันนี้ตั้ง DataModel.GameId ของเกมตัวอย่างปัจจุบันไว้ที่ universeId ที่กำหนด นี่เป็นประโยชน์เมื่อทดสอบไฟล์ rbxl ที่ไม่ได้เผยแพร่บน Roblox เมื่อเป็นไฟล์ท้องถิ่น
เพื่อเข้าถึง DataStoreService ในสถานที่ที่ไม่เผยแพร่ ระหว่าง DataModel:SetUniverseId() และ DataModel:SetPlaceId() ต้องการตั้งค่า
พารามิเตอร์
รหัสที่ต้องการตั้ง DataModel.GameId
ส่งค่ากลับ
อีเวนต์
GraphicsQualityChangeRequest
เปิดเมื่อผู้ใช้ระบุว่าต้องการเพิ่มหรือลดคุณภาพของกราฟิกโดยใช้ปุ่มลัด
เหตุการณ์นี้จะเกิดขึ้นภายใต้เงื่อนไขต่อไปนี้:
- หากผู้ใช้กด F10 เหตุการณ์นี้จะเกิดขึ้นด้วย betterQuality เป็นอาร์เจนต์
- หากผู้ใช้กด ShiftF10 เหตุการณ์นี้จะเกิดขึ้นด้วย betterQuality ของ 0> false0> อาร์เจนต์
เหตุการณ์นี้ไม่ได้ให้ระดับคุณภาพกราฟิกปัจจุบันหรือครอบคลุมการอัปเดตทั้งหมดในคุณภาพกราฟิก ตัวอย่างเช่นการเปลี่ยนแปลงที่ทำในเมนูหลบหนีของ GUI ไม่ได้รับการลงทะเบียน
คุณสามารถดึงกลับค่า Enum.SavedQualitySetting ของผู้ใช้โดยใช้ UserGameSettings ด้วยสแน็ปช็อตต่อไปนี้:
UserSettings():GetService("UserGameSettings").SavedQualityLevel
หากการตั้งค่ากราฟิกของผู้ใช้ถูกตั้งค่าเป็นอัตโนมัติ Enum.SavedQualitySetting จะเป็น Automatic ปัจจุบันไม่มีวิธีที่ผู้พัฒนาจะได้รับระดับคุณภาพกราฟิกของผู้ใช
พารามิเตอร์
ว่าผู้ใช้ได้ร้องขอการเพิ่ม ( จริง ) หรือการลด ( ปลอม ) ในคุณภาพกราฟิก
ตัวอย่างโค้ด
game.GraphicsQualityChangeRequest:Connect(function(betterQuality)
if betterQuality then
print("The user has requested an increase in graphics quality!")
else
print("The user has requested a decrease in graphics quality!")
end
end)
Loaded
เหตุการณ์นี้จะเกิดขึ้นในตัวเล่นเมื่อเกมส์สิ้นสุดการโหลดครั้งแรก
เหตุการณ์ที่โหลดเกิดขึ้นเมื่อเกิดการเลียนแบบทั้งหมดในเกมที่เสร็จสิ้นแล้ว Instances ในเกม
ยกเว้นพวกเขาจะเป็นลูกของ ReplicatedFirst , LocalScripts จะไม่รันก่อนที่จะเกิดเหตุการณ์นี้ สแน็ปช็อตต่อไปนี้จาก LocalScript ใน 1> Class.ReplicatedFirst1>
if not game:IsLoaded() thengame.Loaded:Wait()end
ดูเพิ่มเติม:
- DataModel:IsLoaded() ระบบที่ให้คุณสามารถเลือกได้ว่าจะโหลดเกมหรือไม่
- Instance:WaitForChild() ระบบที่สามารถใช้เพื่อรอให้ Instance ตัวเดียว ๆ ที่จะเลียนแบบโดยไม่ต้องรอให้เกมทั้งหมดโหลด