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;
The output is
nil nil
1 nil
_color and _animation_index are not defined when car.new is called:
local pcar=require("car")
...
function scene:enterScene( event )
local group = self.view
physics.start();
local car1=pcar.new(200,200);
end
Why hasn't the animation_index value changed after assignment?
UPD: I can't assgn to variables with names like rranimation_index too.
rranimation_index=(_animation_index or 1);
rranimation_index=5;
print((_animation_index or 1),rranimation_index);
is:
1 nil
It's not likely to be caused by already used global variables names.