Hi, I’m tryna return a string that indicates if the item is equipped or not but it breaks the loop down - here is with out returning:
here is with returning:
as you can see it stopped looping and do the work.
how would I achieve this?
Hi, I’m tryna return a string that indicates if the item is equipped or not but it breaks the loop down - here is with out returning:
here is with returning:
as you can see it stopped looping and do the work.
how would I achieve this?
I don’t get how you expect return
to work when it is in a for loop?
I knew it’s not gonna work, how would I resolve this?
The thing though is, I can’t do it outside the loop it self.
You cannot run code in the same function after returning. This is an XY problem. Please describe the original problem instead of asking help for something you think is the solution; Running code after returning is not a solution to your original problem.
Certainly. I know what the problem is, I just don’t know how the achieve what I’m trying to do.
Make a variable outside the loop and set that to “Equipped”, “Unequipped”.
And return that variable after the end of the outside of the loop. Replace return statements inside the loop with break.
If you are trying to print all items and then return one of them, you can save the item you want to return in a variable (that has been declared outside the loop), and return the item after the loop has finished. Example:
local item
for i, v in pairs({10, 20, 30}) do
print(v)
if v == 20 then
item = v
end
end
return item