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: Overcoming 1 return

Previous Thread :: Next Thread 
MrNil is not online. MrNil
Joined: 26 Apr 2014
Total Posts: 352
27 Jun 2014 06:09 PM
Do you hate only being able to return 1 value from a ModuleScript when requiring it? "Hate no more!" Here is something that will allow you to load all of the ModuleScript contents directly into the script requiring it, instead of 1 value:

--[[ModuleScript]]--

x,y,z=1,'hi',5

return setmetatable({},{
__call=function(t,t_)
for i,v in pairs(getfenv())do
t_[i]=v
end
end
})

--[[Script]]--
require(ModuleScript)(getfenv())

print(x,y,z) --> 1 'hi' 5

I hope you find this useful.
Report Abuse
EchoReaper is online. EchoReaper
Joined: 14 Oct 2008
Total Posts: 4323
27 Jun 2014 06:13 PM
local content = {}

function content.isOPADamnIdiot()
print("Yes")
end

content.skillLevelOfOP = 0

return content

--script--

local stuff = require(randomModuleScript)

stuff.isOPADamnIdiot()
> Yes

print(stuff.skillLevelOfOP)
> 0
Report Abuse
MrNil is not online. MrNil
Joined: 26 Apr 2014
Total Posts: 352
27 Jun 2014 06:18 PM
the point of this was so that you did not have to refer to a table to grab values
Report Abuse
Radioaktiivinen is not online. Radioaktiivinen
Joined: 25 Apr 2009
Total Posts: 18629
27 Jun 2014 06:26 PM
Why would you ever want to contaminate the global namespace with random variables that may or may not conflict with your own?
Report Abuse
MrNil is not online. MrNil
Joined: 26 Apr 2014
Total Posts: 352
27 Jun 2014 06:50 PM
Im just sharing it with you guys because i find it useful.
Report Abuse
morash is not online. morash
Joined: 22 May 2010
Total Posts: 5834
27 Jun 2014 06:53 PM
I find that returning a table is more organized and you can tell what module your getting your stuff from.
Report Abuse
HUBHUB13 is not online. HUBHUB13
Joined: 15 Oct 2010
Total Posts: 36
27 Jun 2014 08:33 PM
If worse comes to worst, then

return {a,b,c}

--script

local a,b,c=unpack(require(module))
Report Abuse
xSIXx is not online. xSIXx
Joined: 06 Aug 2010
Total Posts: 9202
27 Jun 2014 08:37 PM
"the point of this was so that you did not have to refer to a table to grab values"

... but why not?
Report Abuse
MrNil is not online. MrNil
Joined: 26 Apr 2014
Total Posts: 352
27 Jun 2014 08:52 PM
@bove, At times i find it annoying to reference the returned table of the module repetitively. But thats just me
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