Hi there!
I’m still loving Corona after a month of development, but I’m running into problems. The language is very clear and simple to me in its building blocks, but constructing an elegant and optimised architecture for my platform game, with modules and scopes etc… proves to be quite the challenge for me.
One of the things I’m wondering is how much processing power goes into passing a local parameter along in a function (from another module), as an argument, in comparison to using globals. I’m asking because I keep running into (a LOT) of situations where a local scope doesn’t work for me.
For instance: every frame I need to compare the position of my camera object to the position of my enemy creatures (note to self: I should call this not every frame but every 10 frames or so), to see if the distance is so big that they are offscreen, in which case I stop some calculations for this enemy object. The x and y of these object are in different modules thus out of scope, so I need to make these global values, which is advised against. My other options seems to be to pass along the variables of the enemy x&y as arguments to a function in the camera module.
So… I’m wondering: which is more efficient? And even more: am I doing something very wrong in this way of programming?
Thanks!
t
p.s. I come from a PHP background where require or include are almost like just copy-pasting extra code into another document, and it has nothing to do with scope, and from a OOP background where you just define in every class to what level a function or variable is visible (to whole app, to nothing, to same class etc…). Lua scoping proves difficult for me to grasp. Although the basic explanation seems logical (global = visible everywhere, local = visible inside the code block) everything becomes unclear as soon as I start to use modules. [import]uid: 70134 topic_id: 14272 reply_id: 314272[/import]