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

Why is it in the Mad Bloxxer Tutorial you don't need to clear the activecontestants table?

Asked by 8 years ago

So, this is less asking for help but more just comprehending how Lua works. So, if you haven't seen the tutorial already, when developing the system that checks for how many players currently in the round, the script iterates through all current players like this:

local localtimer = roundtime
while localtimer > 0 do
    wait(1)
    localtimer = localtimer - 1
    timertag.Value = localtimer

    activecontestants = {}
    bloxxeractive = false
    for _, player in pairs(contestants) do
        if player then
            local character = player.Character
            if character then
                local matchtag = character:FindFirstChild("MatchTag")
                local humanoid = character:FindFirstChild("Humanoid")
                if matchtag and humanoid and humanoid.Health > 0 then
                    if player == bloxxer then
                        bloxxeractive = true
                    end
                    table.insert(activecontestants, player)
                end
            end
        end
    end
    if #activecontestants <= 1 or not bloxxeractive then
        break
    end
end

However, there doesn't seem to be a point where anyone is removed from the table, even after the round. How does the script then properly check the amount of players playing?

1 answer

Log in to vote
1
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
8 years ago

Because activecontestants is set explicitly on line 7 of the script you posted, it does not need to be cleared as it gets set to a brand new table after each loop.

So what happened to the other table? Well, once it was no longer being referenced by the variable, it was scooped up by the so called Garbage Collector.

If you want to go into the specifics of this, it gets quite advanced. So instead I'll just leave this link here incase you want to read more into it. There are also some nice articles in the See Also section.

Ad

Answer this question