Quick question. I wanted to go about calling a function while yielding another in order to shorten up code, like so:
--NOTE: This is just an example, and has no real practical uses --f represents function #1 function example(conditional) local var = 0 if conditional then var = f(var) else var = f(var+1) end return var end
Though I didn't know if declaring function f
listed above in the scope of the function example
would be more efficient than in the global scope.
Well if you're only using it in that function, then don't define a second function at all. Write the second function's code directly into that function instead, making it only 1 function. That’s more efficient. But if you don't want to do that, then define it locally right above it, not globally.
However, even if efficiency might differ in multiples, it's pretty much negligible if you're considering game resources.