generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Module question.

Previous Thread :: Next Thread 
DevNotFound is not online. DevNotFound
Joined: 28 Dec 2011
Total Posts: 6752
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
DevNotFound is not online. DevNotFound
Joined: 28 Dec 2011
Total Posts: 6752
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
cntkillme123 is not online. cntkillme123
Joined: 10 Feb 2013
Total Posts: 539
11 Aug 2015 10:28 PM
What do you mean 'settings in the loader'?
Report Abuse
cntkillme123 is not online. cntkillme123
Joined: 10 Feb 2013
Total Posts: 539
11 Aug 2015 10:29 PM
Oh, what are you trying to do?
Report Abuse
DevNotFound is not online. DevNotFound
Joined: 28 Dec 2011
Total Posts: 6752
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 is not online. 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
DevNotFound is not online. DevNotFound
Joined: 28 Dec 2011
Total Posts: 6752
11 Aug 2015 10:32 PM
I don't quite understand.
Report Abuse
Xnite515 is not online. 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
DevNotFound is not online. DevNotFound
Joined: 28 Dec 2011
Total Posts: 6752
11 Aug 2015 10:49 PM
I don't understand.

ss.Var is..?
Report Abuse
Xnite515 is not online. 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
DevNotFound is not online. DevNotFound
Joined: 28 Dec 2011
Total Posts: 6752
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
PearSprite is not online. PearSprite
Joined: 02 Jul 2015
Total Posts: 230
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
cntkillme123 is not online. cntkillme123
Joined: 10 Feb 2013
Total Posts: 539
11 Aug 2015 11:08 PM
You don't need getters/setters in your implementatino, foo.gold = 5 would work fine
Report Abuse
PearSprite is not online. PearSprite
Joined: 02 Jul 2015
Total Posts: 230
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image