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: Why don't local variables appear in getfenv()?

Previous Thread :: Next Thread 
NotAshley is not online. NotAshley
Joined: 16 Jan 2014
Total Posts: 14257
04 Jul 2015 05:03 AM
^
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
04 Jul 2015 05:20 AM
They have a 'local' environment.
getfenv() is used for the 'global' environment.

Like, when you do:

function Random()
x = 1
end

x is global, so it is placed in the global environment, so ALL other things can see it.

But in this:

function Random()
x = 1
local y = 2
end

x is STILL global, and y is LOCAL. So it's only available to its scope, which is the Random function.

So basically, getfenv() retrieves all the GLOBALS because it's available for every thing in the script. Whereas LOCALS are limited to their own scope.

Enjoying your stay at the Scripters Forum? Join this! http://www.roblox.com/My/Groups.aspx?gid=2582784
Report Abuse
NotAshley is not online. NotAshley
Joined: 16 Jan 2014
Total Posts: 14257
04 Jul 2015 05:21 AM
Will getfenv(Random) include its local variables?
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
04 Jul 2015 05:21 AM
No, it will only get the global variables.

Enjoying your stay at the Scripters Forum? Join this! http://www.roblox.com/My/Groups.aspx?gid=2582784
Report Abuse
NotAshley is not online. NotAshley
Joined: 16 Jan 2014
Total Posts: 14257
04 Jul 2015 05:23 AM
What about getfenv() called from inside Random? If not, is there any way to access/change local variables?
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
04 Jul 2015 05:26 AM
Well the only way to change a local variable is to make it a global variable.

Enjoying your stay at the Scripters Forum? Join this! http://www.roblox.com/My/Groups.aspx?gid=2582784
Report Abuse
NotAshley is not online. NotAshley
Joined: 16 Jan 2014
Total Posts: 14257
04 Jul 2015 05:28 AM
Okay, but:


function stuff()
local a = 5
getfenv() -- will this include a?
end
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
04 Jul 2015 05:30 AM
To access local variables, you need to use the debug library. Locals are a part of scope, where the environment isn't.
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
04 Jul 2015 05:30 AM
Nope.

When you remove the local from a, then it would appear.

function stuff()
a = 5
getfenv() -- will this include a?
for i, v in pairs(getfenv()) do
print(i, v)
end
end

stuff()

This one WILL have a.

function stuff()
local a = 5
getfenv() -- will this include a?
for i, v in pairs(getfenv()) do
print(i, v)
end
end

stuff()

This one WON'T have a.


Enjoying your stay at the Scripters Forum? Join this! http://www.roblox.com/My/Groups.aspx?gid=2582784
Report Abuse
NotAshley is not online. NotAshley
Joined: 16 Jan 2014
Total Posts: 14257
04 Jul 2015 05:32 AM
@power well thanks anyway. I understand how to make a variable not local, what I was wondering is specific to a situation.
Report Abuse
2cool4school is not online. 2cool4school
Joined: 02 Dec 2006
Total Posts: 312
04 Jul 2015 05:33 AM
power.... I need to AFAP... when will it be 100% complete?
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
04 Jul 2015 05:34 AM
@Ashley

No problem. C:

@Above

It will be out soon, just finishing off some of the other things.

Enjoying your stay at the Scripters Forum? Join this! http://www.roblox.com/My/Groups.aspx?gid=2582784
Report Abuse
2cool4school is not online. 2cool4school
Joined: 02 Dec 2006
Total Posts: 312
04 Jul 2015 05:37 AM
omg kewl O3O. Cant wait!!!!!!!!!!!

Also, by tw... how old r u?
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
04 Jul 2015 05:38 AM
A bit personal, but it's ok.

I'm actually 9, turning 10 in 1 and a half months.

Enjoying your stay at the Scripters Forum? Join this! http://www.roblox.com/My/Groups.aspx?gid=2582784
Report Abuse
2cool4school is not online. 2cool4school
Joined: 02 Dec 2006
Total Posts: 312
04 Jul 2015 05:40 AM
@power

WOAH O3o

You're birthday is so close to mine :3
Report Abuse
Tynezz is not online. Tynezz
Joined: 28 Apr 2014
Total Posts: 4945
04 Jul 2015 06:41 AM
you're 9??? I thought you were 13
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
04 Jul 2015 08:12 AM
Why would you think that?

Enjoying your stay at the Scripters Forum? Join this! http://www.roblox.com/My/Groups.aspx?gid=2582784
Report Abuse
MiniNob is not online. MiniNob
Joined: 14 May 2013
Total Posts: 822
04 Jul 2015 08:28 AM
So you joined when you were five.
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
04 Jul 2015 08:33 AM
Well, not entirely.

My cousin introduced me to ROBLOX, at the time. My cousin used my account for like the first 6 months then explained to me everything.

Enjoying your stay at the Scripters Forum? Join this! http://www.roblox.com/My/Groups.aspx?gid=2582784
Report Abuse
UFAIL2 is not online. UFAIL2
Joined: 14 Aug 2010
Total Posts: 6905
04 Jul 2015 09:20 AM
So no five, but 6? No difference.
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
04 Jul 2015 09:22 AM
It's actually a 1 year difference.

Enjoying your stay at the Scripters Forum? Join this! http://www.roblox.com/My/Groups.aspx?gid=2582784
Report Abuse
MiniNob is not online. MiniNob
Joined: 14 May 2013
Total Posts: 822
04 Jul 2015 09:24 AM
LOL 2cool4school joined when you were born
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
04 Jul 2015 09:29 AM
:P

It is worth to note, that all I did for the first 2 - 3 years was play games.
Last year I started learning to script.

Enjoying your stay at the Scripters Forum? Join this! http://www.roblox.com/My/Groups.aspx?gid=2582784
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
04 Jul 2015 09:42 AM
Such a maturity example.

My brother's your age and there's no way on Earth I'd be able to have civilized conversations with him like I do you O_O




@Not

The function environment is basically full of that functions "globals", there's no way to access locals without the debug library, but that is not available in RBX.Lua, sorry.

What did you need this for anyway?
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
04 Jul 2015 09:49 AM
I am amazed that this thread turned from a smart discussion about getfenv() to a gossip about my age.

Really?

Enjoying your stay at the Scripters Forum? Join this! http://www.roblox.com/My/Groups.aspx?gid=2582784
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