Difference between functions?

Hi, I’m a total newbie to Corona SDK

what is the difference between

function Draw()

   blah blah

end

and

local Draw = function()

   blah blah

end

Are they pretty much the same except the second function is specifically a local function?

They are exactly the same, except that the first is global.

Notice you can also localize the first method:

[lua]

local function Draw()

  blah blah

end

local Draw=function()

  blah blah

end

[/lua]

The difference between them is that the second method hasn’t been initiated yet, so you can’t call itself - like so:

[lua]

local function Draw()

  Draw() – Ok

end

local Draw=function()

  Draw() – Not ok

end

[/lua]

Of course, the above code would result in a stack overflow, but the point is you can’t reference the second method from within the function.

That’s pretty much the only difference.

C

Thanks ! :smiley:

They are exactly the same, except that the first is global.

Notice you can also localize the first method:

[lua]

local function Draw()

  blah blah

end

local Draw=function()

  blah blah

end

[/lua]

The difference between them is that the second method hasn’t been initiated yet, so you can’t call itself - like so:

[lua]

local function Draw()

  Draw() – Ok

end

local Draw=function()

  Draw() – Not ok

end

[/lua]

Of course, the above code would result in a stack overflow, but the point is you can’t reference the second method from within the function.

That’s pretty much the only difference.

C

Thanks ! :smiley: