So I'm making private modules, but I am not sure how to share variables.
I have tried _G but that does not seem to work
I have also tried doing
1 | require(( 29185912 ) (Product_ID) |
Also once I do it, how would I transfer it the module script and use it?
We use what is called accessors and mutators ie get data (read only) set data (validate then set copy) this is the basics of OOP.
An example would be :-
01 | local vars = { } |
02 | local f = { } |
03 | local get = { } |
04 | local set = { } |
05 |
06 | -- add variables |
07 | vars.a = true |
08 |
09 | -- return a variable |
10 | function get.getA() |
11 | return vars.a |
12 | end |
13 |
14 | -- set variable a |
15 | function set.setA(val) |
Script:-
01 | -- for quicker access make variables to point to our tables |
02 | local module = require(script.Parent.ModuleScript) -- unpack our table into its components |
03 | local get, set, f = module.get, module.set, module.f |
04 |
05 | print (get.getA()) |
06 | f.printA() |
07 |
08 | set.setA( 'Hi' ) |
09 | f.printA() |
10 | set.setA( false ) |
11 | f.printA() |
12 | print (get.getA()) |
Working with private modules can be difficult as allowing the user to input data can leave it vunrable so you should test for this.
I hope this helps