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: is it possible to loop to require modules

Previous Thread :: Next Thread 
lagio2 is not online. lagio2
Joined: 11 Mar 2010
Total Posts: 4001
17 Jun 2017 09:26 AM
so like

local mods = game.ServerStorage.WaveMods:GetChildren()

for i = 1, #mods do
require(mods[i])
end

then could i just call said modules by doing mods[i]()
Report Abuse
AggressiveCatch is not online. AggressiveCatch
Joined: 17 Jul 2011
Total Posts: 5840
17 Jun 2017 09:27 AM
That's fine if modules only run code and don't return a relevant value.

If they do, you'll need to a variable to store the value that the modules returned
Report Abuse
lagio2 is not online. lagio2
Joined: 11 Mar 2010
Total Posts: 4001
17 Jun 2017 09:28 AM
thx bb
Report Abuse
GNUnotUNIX is not online. GNUnotUNIX
Joined: 05 Feb 2012
Total Posts: 15171
17 Jun 2017 09:30 AM
Although they need to return something, but the engine is really forgiving so it won't stop the script from working.


Report Abuse
AggressiveCatch is not online. AggressiveCatch
Joined: 17 Jul 2011
Total Posts: 5840
17 Jun 2017 09:31 AM
They do, but you don't need to store the value of what they returned in your main script if it's just nil or some empty table. That's what I was trying to say.
Report Abuse
lagio2 is not online. lagio2
Joined: 11 Mar 2010
Total Posts: 4001
17 Jun 2017 09:40 AM
aight guys i just tested it and it does call an error

in the module i just left module as nil

so it says No method name passed in __namecall for Object so looks like i do have to do it manually
Report Abuse
AggressiveCatch is not online. AggressiveCatch
Joined: 17 Jul 2011
Total Posts: 5840
17 Jun 2017 09:44 AM
in the module you need to RETURN a value, so like "return nil" at the end of the script

requiring modules in a loop does work, I just tried it
Report Abuse
lagio2 is not online. lagio2
Joined: 11 Mar 2010
Total Posts: 4001
17 Jun 2017 09:46 AM
wait let me see your code
Report Abuse
AggressiveCatch is not online. AggressiveCatch
Joined: 17 Jul 2011
Total Posts: 5840
17 Jun 2017 09:50 AM
in an arbitrary number of modules:

print("Hello World!")
return nil


in the script requiring them:

local modules = LOCATION:GetChildren()

for _, m in pairs (modules) do
require(m)
end
Report Abuse
lagio2 is not online. lagio2
Joined: 11 Mar 2010
Total Posts: 4001
17 Jun 2017 09:56 AM
ohhhh i see what to do now

thanks lol im really new to modules
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