Modules - why doesnt this work?

Main.lua:

ourModule = require (“ourModule”);

ourModule.lua

module(…, package.seeall);

print(mainVariable);

Problem: the variable set in main.lua is not printed in the module

I’m really struggling with Modules - do people generally use them? How on earth do you work with scope between them?

Thanks

Tom

[import]uid: 55068 topic_id: 13551 reply_id: 313551[/import]

Well there are two primary ways of getting data into a module.

  1. Pass it as a parameter.
module = require("module")  
  
module.new(myvariable)  

then

module(..., package.seeall);  
  
function new(mainVariable)  
 print(mainVariable);   
end  

or…
2 Use a global variable using the _G table:

main.lua:  
  
\_G.mainVariable = "fred"  
  
module = require("module")  

and

module(..., package.seeall);  
  
print(\_G.mainVariable);  

[import]uid: 19626 topic_id: 13551 reply_id: 49778[/import]