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: I need help understanding this

Previous Thread :: Next Thread 
cooldude999921 is not online. cooldude999921
Joined: 13 Aug 2011
Total Posts: 3702
23 Apr 2015 10:01 PM
I need a bit more of a clear on

- getfenv()
- setfenv()

idk what these do, lel.


ᴄσσℓɪσs :: ʙᴜɪᴅᴇʀ :: sᴄʀɪᴘᴛᴇʀ :: ᴅᴇᴠᴇʟᴏᴘᴇʀ :: ᴘʀᴏɢʀᴀᴍᴍᴇʀ
Report Abuse
drager980 is online. drager980
Joined: 25 May 2009
Total Posts: 13385
23 Apr 2015 10:05 PM
from my understanding getfenv() returns a table of all variables in the environment
aka
a = "tomato"
print(getfenv()["a"])
-- output is tomato



AND THE TIGER GOES ROAR
Report Abuse
cooldude999921 is not online. cooldude999921
Joined: 13 Aug 2011
Total Posts: 3702
23 Apr 2015 10:08 PM
so setfenv sets variables I think
idk

ᴄσσℓɪσs :: ʙᴜɪᴅᴇʀ :: sᴄʀɪᴘᴛᴇʀ :: ᴅᴇᴠᴇʟᴏᴘᴇʀ :: ᴘʀᴏɢʀᴀᴍᴍᴇʀ
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
23 Apr 2015 10:13 PM
setfenv sets a function's environment to the second argument.
An environment is simply the table of all the global variables, things like print, workspace, etc. are in the environment.

getfenv gets a function's environment (a table, as stated above)
Report Abuse
cooldude999921 is not online. cooldude999921
Joined: 13 Aug 2011
Total Posts: 3702
23 Apr 2015 10:20 PM
so I have:

a=game.Workspace.Part
b=math.fmod(25, 50)
c="Hello World"

and If I use getfenv() it will return the variable name and value?

and if I use setfenv() it changes the returned table with the 2nd arguement (which is a table according to the wiki setfenv (f, table))

ᴄσσℓɪσs :: ʙᴜɪᴅᴇʀ :: sᴄʀɪᴘᴛᴇʀ :: ᴅᴇᴠᴇʟᴏᴘᴇʀ :: ᴘʀᴏɢʀᴀᴍᴍᴇʀ
Report Abuse
cooldude999921 is not online. cooldude999921
Joined: 13 Aug 2011
Total Posts: 3702
23 Apr 2015 10:21 PM
I need like some1 to give me an example on setfenv() if that is to much to ask,

either way thanks for the help and understanding

ᴄσσℓɪσs :: ʙᴜɪᴅᴇʀ :: sᴄʀɪᴘᴛᴇʀ :: ᴅᴇᴠᴇʟᴏᴘᴇʀ :: ᴘʀᴏɢʀᴀᴍᴍᴇʀ
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
23 Apr 2015 10:30 PM
If you have:
a=game.Workspace.Part
b=math.fmod(25, 50)
c="Hello World"


getfenv() will give you a table containing at least those 3 elements. So:
getfenv().a, getfenv().b, and getfev().c would all be those.

setfenv sets locals for the function.

local test = function()
print(x);
end;

setfenv(test, {x = 5; print = print;});
test();

The only globals that exist to that function are now x and print, so workspace would be nil and so on.
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