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;
出力は
nil nil
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の値が変更されないのはなぜですか?
UPD:rranimation_indexのような名前の変数にも割り当てることができません。
rranimation_index=(_animation_index or 1);
rranimation_index=5;
print((_animation_index or 1),rranimation_index);
は:
1なし
すでに使用されているグローバル変数名が原因である可能性は低いです。