Another scope issue - help me understand this

If you have a series of functions in your lua file...

And function A needs to call function B, then function B must appear above it in the lua file.

Unless you remove the 'local' from the start of function B, in which case it can appear after it.

Hope that made sense - can anyone shed light on this please?

Thanks

Tom

its not that you should remove local from function B.
to call a function which is declared after where it is called you should do forward referencing. that means you give definition first and declaration later.

1
2
3
4
5
6
7
8
9
10
11
12
--function B definition --forward referencing
local functionB
 
--function definition and declaration in one line
loca functionA()
  functionB()
end
 
--function B declaration
functionB()
 
end

Ah, thats so obvious! Can't believe I missed that. Thank you!

Tom

views:1309 update:2011/9/27 8:54:05
corona forums © 2003-2011