table 下表从1开始, 不是0
table
也可以 定义之后再添加key(“dirt”)一样
-------------------------------------------------------------------
table数组
下面3种方法来定义table都是合法的,实际上他们都在做同样的事情。3和4的其实是一样的,只是告诉你在这里换行是没有必要的,尤其把table作为函数参数时经常用到。
方法1:
local colorTable = {}
local colorTable = {}
colorTable[1] = "blue"
colorTable[2] = "red"
colorTable[3] = " yellow"
colorTable[4] = "green"
colorTable[5] = "purple”
colorTable[2] = "red"
colorTable[3] = " yellow"
colorTable[4] = "green"
colorTable[5] = "purple”
print( colorTable[3] ) -- output: "yellow”
方法2:
local
local