local windSpeed = 7;
print("WS: " .. windSpeed); --prints 7, as expected
kite.update(windSpeed);
in kite.lua:
function new()
local obj = display.newGroup();
function obj:update(windSpeed)
print("windSpeed here: " .. windSpeed) ; --attempt to concatenate local 'windSpeed' (a nil value)
end
return obj;
end
Why is windSpeed nil in the update method? [import]uid: 52127 topic_id: 10744 reply_id: 310744[/import]
Its being passed as a parameter to the function, so when update is processed, “windSpeed” should be local to that function and is a copy of the data passed to it from the stack.
Least that’s the way most languages deal with passed parameters. However Lua might have issues with stack parameter names being the same as local variables in the calling chunk. It shouldn’t though.
@aaaron - I don’t think that’s the issue. If I change kite.lua to this:
function new()
local obj = display.newGroup();
function obj:update(mySpeed)
print("windSpeed here: " .. mySpeed) ;
end
return obj;
end
I still get the same error. Surely there must be a way to pass a parameter into a function in lua… [import]uid: 52127 topic_id: 10744 reply_id: 39069[/import]