|
| 05 Feb 2016 04:16 PM |
| How do I return a module and then set its function enviroemnt from the script that's required it? |
|
|
| Report Abuse |
|
|
|
| 05 Feb 2016 04:30 PM |
*cough*
#code while wait(1) and x > madness do x = x - 0.01 end |
|
|
| Report Abuse |
|
|
|
| 05 Feb 2016 04:32 PM |
| This is 100% possible and I did it before, hang on I'll try and find it. |
|
|
| Report Abuse |
|
|
|
| 05 Feb 2016 04:33 PM |
Thanks bud, I just get tired of mod.this
#code while wait(1) and x > madness do x = x - 0.01 end |
|
|
| Report Abuse |
|
|
|
| 05 Feb 2016 04:44 PM |
As pike scours through billions of lines of code, plate impatientlywaits in suspends.
*cough* |
|
|
| Report Abuse |
|
|
| |
|
rvox
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 5380 |
|
|
| 05 Feb 2016 04:57 PM |
getfenv(2) or setfenv(2) from a function
ex:
return function() print(getfenv(2).script) end |
|
|
| Report Abuse |
|
|
|
| 05 Feb 2016 05:02 PM |
can I just do something like ( return require(Module) and setfenv(script)-
I dont understand, enlighten me a bit more vox?
#code while wait(1) and x > madness do x = x - 0.01 end |
|
|
| Report Abuse |
|
|
rvox
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 5380 |
|
| |
|
|
| 05 Feb 2016 05:05 PM |
Why would yo
Doesn't this defeat the point of Modules |
|
|
| Report Abuse |
|
|
Tynezz
|
  |
| Joined: 28 Apr 2014 |
| Total Posts: 4945 |
|
|
| 05 Feb 2016 05:06 PM |
return function() for i,v in pairs(module) do getfenv(0)[i]=v end end
change module to table
|
|
|
| Report Abuse |
|
|
|
| 05 Feb 2016 05:22 PM |
the module is a table...
#code while wait(1) and x > madness do x = x - 0.01 end |
|
|
| Report Abuse |
|
|
|
| 05 Feb 2016 05:30 PM |
It doesnt defeat the purpose. Anyone know how to do this? elunate does it
#code while wait(1) and x > madness do x = x - 0.01 end |
|
|
| Report Abuse |
|
|
|
| 05 Feb 2016 06:00 PM |
I don't know how to use setfenv but it should look something like this --module hi = "Hello World"
Env = getfenv() return function() for i,v in pairs(Env) do setfenv(v,{i=i}) end end
---script require(script.ModuleScript)()
|
|
|
| Report Abuse |
|
|
C0D3Y
|
  |
| Joined: 24 Jul 2010 |
| Total Posts: 1692 |
|
|
| 05 Feb 2016 06:03 PM |
I'm probably wrong because I have no experience with environments, but this came to mind when reading the responses:
http://wiki.roblox.com/index.php?title=API:Class/ModuleScript#Advanced_Example |
|
|
| Report Abuse |
|
|
|
| 05 Feb 2016 06:11 PM |
that seems to be what he wants cody
|
|
|
| Report Abuse |
|
|
|
| 05 Feb 2016 06:17 PM |
I dont know if that will work, havent tested it yet. What im looking for is something along the lines of:
module = {}
function module.t() print 'dong!' end
return module
---
require(module)
t()
>dong!
#code while wait(1) and x > madness do x = x - 0.01 end |
|
|
| Report Abuse |
|
|
|
| 05 Feb 2016 06:18 PM |
sorry for such a complex question but this has been bothering me for some time.
#code while wait(1) and x > madness do x = x - 0.01 end |
|
|
| Report Abuse |
|
|
|
| 05 Feb 2016 06:23 PM |
The code cody gave didnt work
#code while wait(1) and x > madness do x = x - 0.01 end |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 05 Feb 2016 06:25 PM |
I haven't read all the replies so woops if you changed the question 'How do I return a module and then set its function enviroemnt from the script that's required it?'
From the module script: return function() setfenv(2, newEnvironment) end
From the script: require(modulescript)() |
|
|
| Report Abuse |
|
|
|
| 05 Feb 2016 06:53 PM |
module
local module = {}
function module.f() print 'dong!' end
return function() setfenv(2, module) end
script
require(script.Parent)()
f()
works
#code while wait(1) and x > madness do x = x - 0.01 end |
|
|
| Report Abuse |
|
|
|
| 05 Feb 2016 06:57 PM |
Thanks cnt, you're great.
#code while wait(1) and x > madness do x = x - 0.01 end |
|
|
| Report Abuse |
|
|
|
| 05 Feb 2016 07:06 PM |
Is there something I can do to where I dont have to call that function on require?
#code while wait(1) and x > madness do x = x - 0.01 end |
|
|
| Report Abuse |
|
|
| |
|
|
| 05 Feb 2016 07:09 PM |
| Is there a way to use that as a callback so I can make something like the include command in C++, where I call a global "require" event that sets the function environment for me? |
|
|
| Report Abuse |
|
|