大致环境:
1.新手入门Android,lua一周
2.cocos2d-quick 3.3rc0
3.ndk-r9d
4.OS X 10.9.5
5…
测试代码:
local a = {}
a.str = “helloworld”
GameState.save(a)
结果:
用Cocos Code IDE的模拟器上运行正常
但是在安卓机上进行真机测试时出现下面的问题
11-11 00:07:22.400: D/cocos2d-x debug info(3008): LUA ERROR: :0: attempt to index upvalue ‘’ (a nil value)
11-11 00:07:22.400: D/cocos2d-x debug info(3008):
11-11 00:07:22.400: D/cocos2d-x debug info(3008): stack traceback:
11-11 00:07:22.400: D/cocos2d-x debug info(3008): : in function ‘encode’
11-11 00:07:22.400: D/cocos2d-x debug info(3008): : in function ‘’
11-11 00:07:22.400: D/cocos2d-x debug info(3008): : in function ‘save’
于是我又试下
测试代码:
local a = {}
a.str = “helloworld”
json.encode(a)
结果:
没有问题
然后翻了下GameState的源代码
function GameState.save(newValues)
local values = eventListener({
name = “save”,
values = newValues,
encode = type(secretKey) == “string”
})
if type(values) ~= “table” then
printError(“GameState.save() - listener return invalid data”)
return false
end
local filename = GameState.getGameStatePath()
local ret = false
if secretKey then
ret = io.writefile(filename, encode_(values))
else
local s = json.encode(values)
if type(s) == "string" then
ret = io.writefile(filename, s)
end
end
printInfo("GameState.save() - update file \"%s\"", filename)
return ret
end
额…不知道怎么办,求大大们指引迷津~折腾了一个晚上了