您的位置:首页 > 编程语言 > Lua

不管是lua还是其它语言,该用结构体的用结构体,不要单独给一个table随便加一个字段

2017-03-13 18:31 537 查看
info模式,什么主动技能  被动技能全是以数据形式存储         管理者manager模式,新手引导数据,一到碰撞等。

之前代码写的不好的地方:

--得到展示的关系列表
function DevelopPathDialog:getDevelopPathRelationList()
local resultShipRelationList = {}  --关联列表
local shipId = self.shipId
local dockyardList = Dict.DockyardList

table.insert(resultShipRelationList, {proptotype = shipId})
for i = 1, #dockyardList do
local dockyard = dockyardList[i]
if dockyard.ship_group == shipId and dockyard.is_legend ~= 1 then  --新增,过滤掉传奇船
table.insert(resultShipRelationList, {proptotype = dockyard.id})
resultShipRelationList.firstLegendId = dockyard.id
elseif dockyard.ship_group == shipId then
resultShipRelationList.firstLegendId = dockyard.id
end
end

return resultShipRelationList
end
这里一个relationShipRelationList,它并不应该去随便加上一个firstLegendId的字段,这样会突然改变它的数据结构,我觉得这样写十分不好。正确做法是:

relationShipRelationInfo = {

list = {},

isFirstLegend = nil,

}

这样以一个结构体去存储,可读性大大提高。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐