Menu
CoddyTech

라운드 반복문

Coddy의 Roblox 게임: 재난 생존 코스 레슨. 20개 중 4번째.

라운드 게임은 끝나지 않습니다. 로비, 라운드, 로비, 라운드가 반복됩니다. 이것은 조건이 항상 참인 while 루프입니다:

while true do
	-- 로비 카운트다운
	-- 라운드
end

end에 도달할 때마다 그 안의 모든 내용이 처음부터 다시 실행됩니다. while true 루프는 절대 끝나지 않으므로 스크립트의 맨 마지막에 놓입니다. 그 뒤에 있는 코드는 실행되지 않습니다. 또한 반복할 때마다 어딘가에서 대기해야 합니다. 그렇지 않으면 루프가 게임의 나머지 부분에 실행 기회를 주지 않아 Roblox가 스크립트를 중지하게 됩니다.

라운드도 Settings.RoundLength부터 카운트다운하므로 플레이어는 얼마나 오래 생존해야 하는지 알 수 있습니다.

challenge icon

챌린지

쉬움

끝나지 않는 게임 루프가 되도록 카운트다운을 바꾸세요.

  1. 카운트다운을 while true do ... end로 감싸세요.
  2. Get ready!를 라운드로 바꾸세요. Settings.RoundLength부터 1까지 1초 간격으로 카운트다운하면서 "Time left: " .. seconds를 표시하세요.

‘플레이’를 누르세요. 남은 시간이 15부터 카운트다운된 다음 로비 카운트다운이 다시 시작됩니다. 그런 다음 ‘확인’을 누르세요.

직접 해보기

local Players = game:GetService("Players")
local Settings = require(game.ReplicatedStorage.Settings)

print("Rounds last " .. Settings.RoundLength .. " seconds")

-- 모든 플레이어의 리더보드에 Wins가 추가됩니다
Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local wins = Instance.new("IntValue")
	wins.Name = "Wins"
	wins.Parent = leaderstats
end)

-- 로비의 상태 게시판
local gui = Instance.new("SurfaceGui")
gui.Parent = workspace.StatusBoard

local status = Instance.new("TextLabel")
status.Name = "Status"
status.Size = UDim2.fromScale(1, 1)
status.BackgroundColor3 = Color3.fromRGB(25, 25, 35)
status.TextColor3 = Color3.fromRGB(255, 255, 255)
status.TextScaled = true
status.Text = "Welcome to Disaster Survival!"
status.Parent = gui

local function setStatus(text)
	status.Text = text
end

-- 레슨 4: 여기에 라운드 루프가 들어갑니다

-- 카운트다운
for seconds = Settings.Intermission, 1, -1 do
	setStatus("Intermission: " .. seconds)
	task.wait(1)
end
setStatus("Get ready!")

Roblox 게임: 재난 생존의 모든 레슨

직접 연습해 보세요: Roblox 플레이그라운드