Correct way to modularize code?

I’ve been using the following modularization approach in the recent blog article:

gamefunctions.lua

function doSomething()  
 -- something  
end  

level.lua

local myFunction = gamefunctions.doSomething()  

When using this approach, I can’t access any variables in one file from the other file unless it’s global (with _G.). Same goes for no -variables like groups. LUA seems to treat them as two completely different files.

For this reason, I am using a lot of global variables to communicate between the two files. Is this normal?

Also, if I use global variables, as long as I clean them (remove and nil them out) does it make any difference from using local vars?
[import]uid: 39031 topic_id: 17529 reply_id: 317529[/import]

I’m not sure which blog you read but there are actually three :wink:

http://blog.anscamobile.com/2011/07/using-external-modules-in-corona/
http://blog.anscamobile.com/2011/08/tutorial-simple-modular-coding-technique/
http://blog.anscamobile.com/2011/09/a-better-approach-to-external-modules/

Take a look at those, I’m sure they can help you.

Peach :slight_smile: [import]uid: 52491 topic_id: 17529 reply_id: 66616[/import]