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

How do I make a loop only return one value?[Solved]

Asked by 5 years ago
Edited 5 years ago

I have the loop finding the names of frames in "Slots". I want the loop to end once it found just one slot that fits the category. If there are other slots as duplicates I want them to be left alone. How do I do this?

for i,v in pairs(Slots)do
    if v:IsA("Frame")then
        if v.Name == BeltName then
            v:Destroy()
            for _,R in pairs(Slots)do
                if R.Name ~= v.Name then
                     if R.Position == v.Position then
                     R.SlotUsed.Value = "false"
                     v:Destroy()
                     break
                     end
                end
            end
        end
    end
end
0
Holdup I think I solved it by using return instead of break, But I'm still testing it. songboy50 77 — 5y
0
Remember that "return" in most languages including Lua usually refers to the act of returning a value or values from a function/method. Using return in this context could cause some confusion. The difference between break and return are that break exits out of the loop in context, while return exits out of the function in context. davidgingerich 603 — 5y
0
Lol, I fixed it but I'll keep it here just for further refrence. songboy50 77 — 5y

Answer this question