【发布时间】:2013-03-10 14:55:51
【问题描述】:
local car={};
local car_mt = { __index=car };
function car.new(_x, _y,_color,_animation_index)
local ncar=
{
x=_x or 0;
y=_y or 0;
color=_color or 0x005500;
print(_animation_index,animation_index);
animation_index=(_animation_index or 1);
print((_animation_index or 1),animation_index);
}
return setmetatable(ncar,car_mt);
end
return car;
输出是
无无
1 无
调用car.new时没有定义_color和_animation_index:
local pcar=require("car")
...
function scene:enterScene( event )
local group = self.view
physics.start();
local car1=pcar.new(200,200);
end
为什么赋值后animation_index的值没有变化?
更新: 我也无法分配名称为 rranimation_index 的变量。
rranimation_index=(_animation_index or 1);
rranimation_index=5;
print((_animation_index or 1),rranimation_index);
是:
1 无
这不太可能是由已使用的全局变量名称引起的。
【问题讨论】:
-
本地附近出现意外符号
-
先修复编译器错误。