I am creating an external module to easily make something. How would I identify the object, so that I can call “myObject=externalLib.newThing{params1=50, params2=90}” and then “myObject.x, myObject.y=500, 500”? As it says, “attempt to index global ‘myObject’ (a nil value)” [import]uid: 147322 topic_id: 27571 reply_id: 327571[/import]
Please help! [import]uid: 147322 topic_id: 27571 reply_id: 112073[/import]
Very rough example;
[lua]–main.lua
require “test”
local myObject = test.spawn(100,100)
myObject.x = 200[/lua]
and
[lua]–test.lua
module (…, package.seeall)
function spawn(x, y)
myObject = display.newCircle(x, y, 20)
return myObject
end[/lua]
That will work. One thing to make sure you are doing is returning “myObject” at the end of the function.
Peach
[import]uid: 52491 topic_id: 27571 reply_id: 112144[/import]
To expand on peach’s example (module thing is depreciated + it’s best not to use it)
[lua]–main.lua
local test = require (“test”)
local myObject = test:spawn(100,100)
myObject.x = 200[/lua]
and
[lua]–test.lua
local public = {}
function public:spawn(x, y)
local myObject = display.newCircle(x, y, 20)
return myObject
end
return public[/lua] [import]uid: 84637 topic_id: 27571 reply_id: 112178[/import]
Resolved! You can mark it now. [import]uid: 147322 topic_id: 27571 reply_id: 112227[/import]
Thanks Danny - that will teach me to answers threads so late at night 
We also have a blog on that that may be useful for you binc, see here; http://www.coronalabs.com/blog/2011/09/05/a-better-approach-to-external-modules/
Peach
[import]uid: 52491 topic_id: 27571 reply_id: 112244[/import]
Great! Thanks for the link. I was about to start on making an enormous external library, and now, instead of having to redo it, I can just start with that approach. Thanks again! [import]uid: 147322 topic_id: 27571 reply_id: 112298[/import]
Great
Good luck with your project! [import]uid: 52491 topic_id: 27571 reply_id: 112474[/import]