Hello!
Function:
function table:rebuild()
if type(self) == "table" then
local Rebuilded = {}
for i=1, #self do
if self[i] then
Rebuilded[#Rebuilded+1] = self[i]
else
print(i,"--")
end
end
print(#Rebuilded, "#objs")
return Rebuilded
else
error("Cant rebuild table")
end
end
Video:
bandicam 2020-09-01 00-34-56-120
Question: Why is the function not working correctly? Why doesn’t it write “num --”(print(i,"–") in the code) after each deletion of an object?
PS:
Function where I am using table:rebuild()
function SpriteImgs:UpdatePositionOfSpells()
if ((#self["metadata"]["stats"]["spells"]["list"]) == 0) then do return end end
local IsHero = false
if self.metadata["character"]["prefix"] == "hero" then
IsHero = true
end
self.metadata["stats"]["spells"]["list"] = table.rebuild(self.metadata["stats"]["spells"]["list"])
local TableOfSpells = self.metadata["stats"]["spells"]["list"]
local GetX
local GetY = - 25
if IsHero then
GetX = - (self.width*0.30)
else
GetX = (self.width*0.30)
end
for i=1, #TableOfSpells do
local GetObj = TableOfSpells[i]["img"]
GetObj.x = GetX - (i*(GetObj.width*1.15))
GetObj.y = GetY
end
end