I’m starting to really confuse myself (happens when the coffee wears off).
I’ve been studying up on how to utilize external modules appropriately. Or at least not use them incorrectly.
But I’m still having issues.
Here are the links I’ve been reading and practicing from:
http://www.coronalabs.com/blog/2011/08/12/tutorial-simple-modular-coding-technique/
This post is very cool, and gives some great points on how to stop duplicating code, by putting your mostly used functions inside one place - then calling that single file across multiple modules.
What confuses me is level1.lua does not have the module(…, package.seeall) in the top, as I would expect. Is it not needed?
Now, when you go to this post:
http://www.coronalabs.com/blog/2011/07/06/using-external-modules-in-corona/
I think I see the opposite in effect. The example of their level1.lua has the module(…, package.seeall) in the top.
Like many apps, I plan to put all my screen content inside separate screen.lua files. I also plan to place common functions inside a single Functions.lua file. (btw, is it best to reference the Functions.lua from inside the main.lua or from inside each screen.lua file?
I intend for my main.lua to be simply the calling-entity to everything else.
I come from a PHP web background, and I usually place every custom function inside a single file, and call that file from each page. (even if most of the functions are not used in that page) Perhaps this is bad practice for the mobile side?
And inside each screen.lua I am calling the removeSelf() function, to clean up memory.
Does this clean up the references to external modules too? I can’t image it does, since the removeSelf() is attached to an display object.
Example:
-- level1.lua (pulled this from the first link above)
--------------------------------------------------
function new()
local gamefunctions = require( "gamefunctions" ) --\> this is called inside the level1.lua, not main.lua?
-------more game code below.........
end
And back to the original concern, when do I really need to place module(…, package.seeall) in the top of a file, and when don’t I?
It seems I can leave it out, and I get the same results (at least from what I’ve tested)
thanks guys!
[import]uid: 154122 topic_id: 28273 reply_id: 328273[/import]
I’ll try to answer a few of them.