Reduce Code

Hello,

I am trying to reduce the amount of code I'm using. I have a lot of repetitive code that I would like to get rid of an use only once. I was thinking of adding the code in a document called extraCode.lua, then on every level calling it. But it does not work, there are images and functions. I just want to reduce my code, any ideas?

Thanks.

If you want to reduce your code, make a function in another document. Then whenever you want to activate that function, call the function like callMe(). You have to remember to do require "extraCode" in the beginning of you file. Also make sure that your functions are not local.

Regards,
Jordan Schuetz
Ninja Pig Studios

the best way to create "external" modules is this:

external.lua

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 -- create a table that holds your functions
local funcs = {} 
 
-- create functions like this:
funcs.myAwesomeFunction1 = function ( param1, param2 )
  local p1 = param1
  local p2 = param2  
  local p3 = p1 + p2
  return p3
end
 
funcs.myAwesomeFunction2 = function ( param1, param2 )
  local p1 = param1
  local p2 = param2  
  local p3 = p1 - p2
  return p3
end
 
-- at the end of your module return the functions-table
return funcs
views:1555 update:2011/12/29 9:44:01
corona forums © 2003-2011