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: Setfenv and stuff

Previous Thread :: Next Thread 
checkplate is not online. checkplate
Joined: 05 Jan 2016
Total Posts: 1379
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
checkplate is not online. checkplate
Joined: 05 Jan 2016
Total Posts: 1379
05 Feb 2016 04:30 PM
*cough*

#code while wait(1) and x > madness do x = x - 0.01 end
Report Abuse
wonderful72pike is not online. wonderful72pike
Joined: 13 Jul 2010
Total Posts: 7009
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
checkplate is not online. checkplate
Joined: 05 Jan 2016
Total Posts: 1379
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
checkplate is not online. checkplate
Joined: 05 Jan 2016
Total Posts: 1379
05 Feb 2016 04:44 PM
As pike scours through billions of lines of code, plate impatientlywaits in suspends.

*cough*
Report Abuse
checkplate is not online. checkplate
Joined: 05 Jan 2016
Total Posts: 1379
05 Feb 2016 04:55 PM
Pike?
Report Abuse
rvox is not online. 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
checkplate is not online. checkplate
Joined: 05 Jan 2016
Total Posts: 1379
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 is not online. rvox
Joined: 18 Feb 2011
Total Posts: 5380
05 Feb 2016 05:03 PM
Wait, i misunderstood
Report Abuse
Happywalker is not online. Happywalker
Joined: 05 Mar 2010
Total Posts: 3672
05 Feb 2016 05:05 PM
Why would yo

Doesn't this defeat the point of Modules
Report Abuse
Tynezz is not online. 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
checkplate is not online. checkplate
Joined: 05 Jan 2016
Total Posts: 1379
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
checkplate is not online. checkplate
Joined: 05 Jan 2016
Total Posts: 1379
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
LegendaryAccount is not online. LegendaryAccount
Joined: 02 Jun 2010
Total Posts: 13193
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 is not online. 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
LegendaryAccount is not online. LegendaryAccount
Joined: 02 Jun 2010
Total Posts: 13193
05 Feb 2016 06:11 PM
that seems to be what he wants cody


Report Abuse
checkplate is not online. checkplate
Joined: 05 Jan 2016
Total Posts: 1379
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
checkplate is not online. checkplate
Joined: 05 Jan 2016
Total Posts: 1379
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
checkplate is not online. checkplate
Joined: 05 Jan 2016
Total Posts: 1379
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 is not online. 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
checkplate is not online. checkplate
Joined: 05 Jan 2016
Total Posts: 1379
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
checkplate is not online. checkplate
Joined: 05 Jan 2016
Total Posts: 1379
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
checkplate is not online. checkplate
Joined: 05 Jan 2016
Total Posts: 1379
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
LegendaryAccount is not online. LegendaryAccount
Joined: 02 Jun 2010
Total Posts: 13193
05 Feb 2016 07:08 PM
nope


Report Abuse
wonderful72pike is not online. wonderful72pike
Joined: 13 Jul 2010
Total Posts: 7009
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
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