有没有比“其他马拉松”更简单的方法?

时间:2012-01-27 14:56:00

标签: lua

如何优化此代码?

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

功能更长,这就是为什么我可以使用更简单的方法:)

1 个答案:

答案 0 :(得分:5)

您应该将颜色存储在数组中:

colors = { all your colors }

moveLine = function()
    first = colors[variable]
    second = colors[variable + 1]
    variable = variable + 1
end