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: require() doesn't load ModuleScript?

Previous Thread :: Next Thread 
ked2000 is not online. ked2000
Joined: 10 Jul 2011
Total Posts: 1059
23 Jul 2015 10:42 PM
I am trying to navigate through my project with my function GetLib(string ...). GetLib() is designed to take a string path from the tuple, find the ModuleScript, and create a copy of it.

After the first iteration, the script seems to stop(not error) when require() is called.

Directory Map:

-ModuleScript "MainModule"
--Folder "Lib"
---ModuleScript "Log"
---Folder "UI"
----ModuleScript "UI"


Source:

function GetLib(...)
local result = {};
for i, path in next, {...} do

-- ModuleScript Aux gets the module script from string "path"

local module = Aux.GetPath(path, script:WaitForChild("Lib"), '.');
if (path:match("[^%.%s]+$"):lower() == module.Name:lower()) then
local imported = require(module);

-- Make a copy
local copy = {};

-- Format functions
if (type(imported) == "table") then
for name, data in next, imported do
if (type(data) == "function") then
copy[name] = function(self, ...)
return data(self, C, ...);
end
else
copy[name] = data;
end
end
elseif (type(imported) == "function") then
copy = function(...)
return imported(C, ...);
end
end

result[#result+1] = copy;
end
end

return unpack(result);
end


Logger, UI = GetLib("Log", 'UI.UI');



Logger is retrieved successfully but on the second iteration where path = "UI.UI", the script waits for require(module) but require(module) never returns ModuleScript "UI".

Why is this happening?
Report Abuse
darkemosoul is not online. darkemosoul
Joined: 13 Dec 2008
Total Posts: 458
23 Jul 2015 10:46 PM
First can you explain to me what your doing?


Where exactly are you calling it? Unless you indent its really hard to follow.
Report Abuse
darkemosoul is not online. darkemosoul
Joined: 13 Dec 2008
Total Posts: 458
23 Jul 2015 10:47 PM
not indent but show me where you are calling it, very confusing which script is which to btw
Report Abuse
ked2000 is not online. ked2000
Joined: 10 Jul 2011
Total Posts: 1059
23 Jul 2015 10:53 PM
@darkemosoul

I am calling it here:

Logger, UI = GetLib("Log", 'UI.UI');
Report Abuse
darkemosoul is not online. darkemosoul
Joined: 13 Dec 2008
Total Posts: 458
23 Jul 2015 10:58 PM
-- Format functions
if (type(imported) == "table") then

Check that section, you never

return imported
Report Abuse
ked2000 is not online. ked2000
Joined: 10 Jul 2011
Total Posts: 1059
23 Jul 2015 10:59 PM
That is intentional, I return "copy" at the end instead.
Report Abuse
ked2000 is not online. ked2000
Joined: 10 Jul 2011
Total Posts: 1059
23 Jul 2015 11:00 PM
I mean, add it to the result table.
Report Abuse
darkemosoul is not online. darkemosoul
Joined: 13 Dec 2008
Total Posts: 458
23 Jul 2015 11:02 PM
But then why are you using unpack()? Is the module returning an array of functions?
Report Abuse
iiEssence is not online. iiEssence
Joined: 18 Jun 2014
Total Posts: 3467
23 Jul 2015 11:03 PM
Does the module UI return?


I don't need a siggy
Report Abuse
ked2000 is not online. ked2000
Joined: 10 Jul 2011
Total Posts: 1059
23 Jul 2015 11:05 PM
The function returns every requested module to its respective variable.

Logger, UI = GetLib("Log", 'UI.UI');

The ModuleScript "Log" is now stored in the variable Logger, and the ModuleScript "UI" is now stored in the variable UI.
Report Abuse
ked2000 is not online. ked2000
Joined: 10 Jul 2011
Total Posts: 1059
23 Jul 2015 11:07 PM
@iiEssence

UI returns a table.
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