Why Type Of Function Parameter Change ?

 local function createHero(id,gx,gy) local s = require("sprite.Sprite") print("id="..id) -- print a number ,for example 10 local h = s:getHero(id) end

function in sprite.Sprtie module like this function getHero(id) print("id",id) -- print a table, why table? should be number end

why print a table ,it should be number.

Hi there,

I think the reason is your use of the colon method.  In Lua, s:getHero(id) is a syntactic shorthand for getHero(s, id).  (You can learn more about that here: http://www.lua.org/pil/5.html).  Thus, your getHero function is actually getting two arguments, not one.  The first one it’s getting is s, and that’s what’s being assigned to the id variable and being printed.

Hope this helps.

  • Andrew

thanks Andrew,you are right.

Hi there,

I think the reason is your use of the colon method.  In Lua, s:getHero(id) is a syntactic shorthand for getHero(s, id).  (You can learn more about that here: http://www.lua.org/pil/5.html).  Thus, your getHero function is actually getting two arguments, not one.  The first one it’s getting is s, and that’s what’s being assigned to the id variable and being printed.

Hope this helps.

  • Andrew

thanks Andrew,you are right.