Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

GOTO Line Help?

Asked by 10 years ago

Is there a GOTO command in ROBLOX? It would be very useful. If not is there any workarounds?

for i = 1, 30 do
    wait(1)
    if game.Players.NumPlayers < 2 then
        break
    end
end
if game.Players.NumPlayers < 2 then
    while true do
        if game.Players.NumPlayers > 1 then
            break
        end
        wait()
    end 
end

I'm making a script for my fighting game. And it is supposed to run a 30 second intermission. But if there is only one player left, it waits for a new player then restarts the intermission timer.

1 answer

Log in to vote
3
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

No. Lua supports goto only from 5.2 beta versions and on; ROBLOX is stable 5.1.

It is a general consensus (though this is debated) that gotos are rarely what you want to use to solve a problem.


break (not "continue" -- Lua doesn't have continue -- mistake -- thank you TaslemGuy) act as a form of limited jumping.

Functions are a very powerful way to define routines.


If you specify a particular problem, we could describe a good solution (that doesn't need goto)


First, I would definitely simplify the second loop you have:

while game.Players.NumPlayers < 2 do
    wait()
end

I'm not exactly sure what you want to do. I don't see any particular point where you would want to act.

But speaking very generally, this is an architecture that might work for you:

local modes = {}

function modes.intermission()
    for i = 1, 30 do
        wait(1)
        if game.Players.NumPlayers < 2 then
            return "waitForPlayers"
            break
        end
    end
    return "playGame"
end

function modes.waitForPlayers()
    while game.Players.NumPlayers < 2 do
        wait()
    end
    return "intermission"
end

----

local mode = "intermission"
while true do
    mode = modes[mode]()
    wait()
end

Clever breaks and ifs would also work, but could get to be a mess with a larger script.

0
I edited, please look Protoduction 216 — 10y
1
One note: Lua does not have a `continue` keyword. TaslemGuy 211 — 10y
Ad

Answer this question