|
| 11 Aug 2015 10:26 PM |
| When loading a module, can you have settings in the loader without using global variables? If so, how? |
|
|
| Report Abuse |
|
|
|
| 11 Aug 2015 10:27 PM |
| I want the variables in the loader to transfer over to the MainModule without using _G. variables. |
|
|
| Report Abuse |
|
|
|
| 11 Aug 2015 10:28 PM |
| What do you mean 'settings in the loader'? |
|
|
| Report Abuse |
|
|
|
| 11 Aug 2015 10:29 PM |
| Oh, what are you trying to do? |
|
|
| Report Abuse |
|
|
|
| 11 Aug 2015 10:30 PM |
So lets say the module is an asset id 23454523.
There will be another script that goes under ServerScriptService that will require the module. So it will be:
require(23454523)
Now the settings I am talking about is variables that would go under loader, for example:
require(23454523) perks = true players = 3
I want those perks and players variables to transfer over to the modular script. So the modular script could be scripted in such way:
if perks == true then
elseif perks == false then
end |
|
|
| Report Abuse |
|
|
CrowClaws
|
  |
| Joined: 04 Jul 2010 |
| Total Posts: 4466 |
|
|
| 11 Aug 2015 10:32 PM |
if you make any changes to a module script with a script those changes will only apply to that script |
|
|
| Report Abuse |
|
|
| |
|
Xnite515
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 22763 |
|
|
| 11 Aug 2015 10:46 PM |
no
you cannot do that but you can assign require() as a variable and put
ss = require() ss.Var = asdsdasasdasddas
i believe |
|
|
| Report Abuse |
|
|
|
| 11 Aug 2015 10:49 PM |
I don't understand.
ss.Var is..?
|
|
|
| Report Abuse |
|
|
Xnite515
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 22763 |
|
|
| 11 Aug 2015 10:52 PM |
its just a example
ok so
module:
function lala(a) print(a) end
return lala
script:
a = require(module) a('hi')
|
|
|
| Report Abuse |
|
|
|
| 11 Aug 2015 10:52 PM |
oh so..
Module:
function variable(value) AVariable = value end return variable
Script:
require(module) variable(3)
would that make AVariable a variable with a value of 3?
[2] |
|
|
| Report Abuse |
|
|
|
| 11 Aug 2015 11:03 PM |
To have settings for each script that requires the module, you should make a class like so:
-- module local foo = { }
function foo.new( self, ... ) local object = { } local settings = { ... } for k, v in pairs( settings ) do object[k] = v end
return setmetatable( object, { __index = foo } ) end
function foo.Get( this, setting ) return this[setting] end
function foo.Set( this, setting, value ) this[setting] = value end
return setmetatable( foo, { __call = foo.new } ) -- main script local foo = require( 12341234 )( { gold = 100, xp = 50 } ) print( foo:Get 'gold' ) -- 100 print( foo:Get 'Gold' ) -- nil print( foo:Get 'xp' ) -- 50 foo:Set( 'gold', 1337 ) print( foo:Get 'gold' ) -- 1337
|
|
|
| Report Abuse |
|
|
|
| 11 Aug 2015 11:08 PM |
| You don't need getters/setters in your implementatino, foo.gold = 5 would work fine |
|
|
| Report Abuse |
|
|
|
| 11 Aug 2015 11:15 PM |
| Well yeah. I'm just used to the OOP paradigm of keeping everything private, so that way if you need to update multiple settings upon updating one setting/property, then you can. |
|
|
| Report Abuse |
|
|