【已解决】cocos2dx 3.0以上版本 lua 里的 array dictionary 怎么用

2.0 的lua 里有CCArray 这东西 3.0以上版本 lua里的 数组 和字典怎么用呢?

用Lua的原生table。
比如数组:{1, 2, 3, 4}
字典:{x=1, y=2}

好的 谢了!!

local array = {5,6,7,8,“adsasda”}
local array1 = { name = “jhon”,age = 34 }

print("table lenth ==".. table.maxn(array1))

再问一下啊 table.maxn 和 table.getn 这两个 函数都 求不出 array1 这种表的 总数 能问下 改怎么求 array1 的元素的个数吗

对dictionary而言,想知道有多少个filed,只能遍历。

function tablelength(T)
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
end

建议多看看Lua的语言教程。这个跟cocos2d-x无关的。

好的 最近游戏要用 lua 上来就开始写 lua 语法有的 还不懂呢 多谢