如何优化此代码?
variable = 1
moveLine = function ()
if variable == 1 then
first = color_1.color
second = color_2.color
elseif variable == 2 then
first = color_2.color
second = color_3.color
end
variable = variable + 1
end
功能更长,这就是为什么我可以使用更简单的方法:)
答案 0 :(得分:5)
您应该将颜色存储在数组中:
colors = { all your colors }
moveLine = function()
first = colors[variable]
second = colors[variable + 1]
variable = variable + 1
end