|
| 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
|
  |
| 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 |
|
|
|
| 23 Apr 2015 10:08 PM |
so setfenv sets variables I think idk
ᴄσσℓɪσs :: ʙᴜɪᴅᴇʀ :: sᴄʀɪᴘᴛᴇʀ :: ᴅᴇᴠᴇʟᴏᴘᴇʀ :: ᴘʀᴏɢʀᴀᴍᴍᴇʀ |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|