如何让 lua 在 while true 循环中停止 if 循环?

How would I make a lua stop an if loop inside a while true loop?

这是一个很难问的问题,因为我不可能将所有问题都放入一个问题中,但我可以解释这个问题。我的游戏 logic/game 脚本本质上是:

function game()
-- stuff
end

while true do
    while players < 2 do
     -- tell player to invite more players and all that jazz
    end

    if players >= 2 then
       game()
    end
end

(这只是伪代码,为了简单起见,我忽略了 wait() 和 Roblox API 之类的东西,因为这个想法仍然是相同的,但我认为这个问题对于一般的编程来说已经足够普遍了)

现在,在我的 'game' 函数中,当玩家准备就绪时(即不在菜单中等),它会将所有准备就绪的玩家传送到游戏所在的位置。不幸的是,由于 'game()' 一直是 运行,玩家不断地被传送,而且不会停止。我不确定如何做到即使 'game()' 一直是 运行.

也只能传送一次

这里是传送的代码,无需 Roblox 知识即可简单解释 API:

if #ready >= 2 then -- if the players in the list 'ready' (the players that are ready to start the game) 
    print(player.Name .. " moved") -- show which player is moved
    player:MoveTo(--place where the game is)) -- actually move the player
end

问题在于,由于 'game()' 一直处于 运行,因此玩家不断地移动到游戏所在的位置(使他们无法移动)。在所有玩家移动后,如何让 Lua 停止移动玩家?我尝试使用 for 循环,但由于 'game()' 正在重复,因此也不断重复。我希望 Lua.

方面的任何知识渊博的人都能理解这一点

在我看来,您想维护两个列表:当前正在玩和希望玩。

我不确定你的逻辑到底是什么(人们可以加入正在进行的游戏吗?),但基本的想法是你只会 运行 列表中的游戏希望玩的玩家,而不是当前玩的玩家。