1.if … elseif
if parentName == "UpLeft" then
self:SetChildPosByParam(3,3,107,100,20)
elseif parentName == "UpRight" then
self:SetChildPosByParam(5,5,-107,-100,-20)
elseif parentName == "DownLeft" then
self:SetChildPosByParam(4,4,0,0,0)
elseif parentName == "DownRight" then
self:SetChildPosByParam(4,4,0,0,0)
end
--这样是可以的,但这样写不行
if parentName == "UpLeft" then
self:SetChildPosByParam(3,3,107,100,20)
elseif parentName == "UpRight" then
self:SetChildPosByParam(5,5,-107,-100,-20)
else
self:SetChildPosByParam(4,4,0,0,0)
end
--原因应该是parentName不能是string类型的
2.for循环遍历List
如果是想清空一个List
如果list是默认顺序table.insert就可以这样清空
for i = 1, #self.List do
if List[i] then
--制空List操作
end
end
但如果不是顺序table.insert而是table.insert指定下标
用for i = 1, #self.List do
-- 制空List操作
end --是不行的
--原因看列表长度时 #List 是个坑请慎重用(如果List下标是这样 1 2 4 5)看列表长度时用#就只能返回2个长度
-- #List 和 ipairs这个是一样的
-- 可以用
for _, item in pairs(List) do
-- 制空List操作
end