Page 2 of 2
Re: Help with Inventory system!
Posted: Sun Jun 16, 2024 3:36 pm
by H.I
RNavega wrote: ↑Mon Jun 10, 2024 12:43 am
H.I wrote: ↑Sat Jun 08, 2024 8:15 am
Hi. In that code the loops are redundant as you're not using the "x" and "y" variables.
The function can be reduced to just this line, "self.arr[iy][ix] = 0"
Thank you for noticing, i guess i didn't notice that.
Re: Help with Inventory system!
Posted: Mon Jun 17, 2024 1:41 am
by RNavega
H.I wrote: ↑Sun Jun 16, 2024 3:36 pm
Thank you for noticing, i guess i didn't notice that.
Reading it again, I should've said "the way that the loops are used", without mentioning the index variables, because you can have a totally useful loop where the index variable happens to not be used.
For example:
Code: Select all
-- Saving time by both emptying a table and calling a method of its items.
for unusedVariable = 1, #myTable do
local myItem = table.remove(myTable)
myItem:method()
(...)
end
Edit: that is more performant than "while #myTable > 0" because it only calculates the table length once, when the FOR loop starts, instead of on each iteration of that WHILE.