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 » Scripting Helpers
Home Search
 

Re: Tables and Scopes.

Previous Thread :: Next Thread 
Quenty is not online. Quenty
Joined: 03 Sep 2009
Total Posts: 9316
29 Mar 2012 08:09 PM
If I do....

do
local atable = {Hehe = "Hello", Thing={OtherThing={}}}
function FindThingInTable(table)
for a, b in pairs(table) do
if b.Hehe=="Hello" then
return b.Thing.OtherThing;
end
end
end

local x = FindThingInTable(atable)
x.OtherOtherThing = "DFDF"
end

Would:

print(atable.Thing.OtherThing.OtherOtherThing)

result in "DFDF"?

Can I return an index of a table and use it?
Report Abuse
pwnedu46 is not online. pwnedu46
Joined: 23 May 2009
Total Posts: 7534
29 Mar 2012 08:15 PM
a would be the index, b returns the value: "Hello" in this case.
Report Abuse
Quenty is not online. Quenty
Joined: 03 Sep 2009
Total Posts: 9316
29 Mar 2012 08:22 PM
Hmm...... so if I return a then would I end up with...

atable.Thing.OtherThing
Report Abuse
crazytomato4 is not online. crazytomato4
Joined: 09 Feb 2011
Total Posts: 1368
29 Mar 2012 08:35 PM
No.

First of all:

"function FindThingInTable(table)"

"table"

STOP OVERWRITING LIBRARIES

Second, 'b' for the first repetition would be the string "Hello", which does not have a 'Hehe' property of any sort, causing an error. The second iteration (were it to actually get to the second iteration), 'b' would equal atable.Thing, which does not contain a 'Hehe' index either.

Third:


local x = FindThingInTable(atable)

atable isn't define, it went out of scope.

As for the stuff about being able to change a table outside of the scope in which it was defined, you can do that as long as you have a reference to the table. That print line would have to be inside the scope of the table, though, else it would just error.
Report Abuse
oxcool1 is not online. oxcool1
Joined: 05 Nov 2009
Total Posts: 15444
29 Mar 2012 08:37 PM
[ Content Deleted ]
Report Abuse
oxcool1 is not online. oxcool1
Joined: 05 Nov 2009
Total Posts: 15444
29 Mar 2012 08:39 PM
[ Content Deleted ]
Report Abuse
crazytomato4 is not online. crazytomato4
Joined: 09 Feb 2011
Total Posts: 1368
29 Mar 2012 08:41 PM
"He can use getfenv(0).table"

No, he can't. He could use getfenv(2).table I think, but it's much easier and much better practice to NOT OVERWRITE THINGS.

"Nope its IN the scope."

...

Do you have any idea at all what you're talking about?
Report Abuse
oxcool1 is not online. oxcool1
Joined: 05 Nov 2009
Total Posts: 15444
29 Mar 2012 08:46 PM
[ Content Deleted ]
Report Abuse
epicfail22 is not online. epicfail22
Joined: 25 Sep 2009
Total Posts: 3739
29 Mar 2012 08:50 PM
May I ask why you used 'do' at the beginning?
Report Abuse
Quenty is not online. Quenty
Joined: 03 Sep 2009
Total Posts: 9316
29 Mar 2012 08:53 PM
Just to set the scope. That WAS an example, not my real code, which isn't NEARLY that sloppy.

Anyway, thanks guys. :D
Report Abuse
crazytomato4 is not online. crazytomato4
Joined: 09 Feb 2011
Total Posts: 1368
29 Mar 2012 08:54 PM
"But its defined, its still inside the scope."

Pretty sure you have no idea what you're talking about. Which scope are you saying it's inside? Because it most definitely isn't defined in the scope where he tried to use it from.

"Yes, he can. Level 0 is the script's environment."

No, it's not.
Report Abuse
crazytomato4 is not online. crazytomato4
Joined: 09 Feb 2011
Total Posts: 1368
29 Mar 2012 08:56 PM
Nevermind. Haven't used Lua in too long. You're right about the getfenv(0) thing.

However, I still don't understand what the heck you're talking about with the scopes.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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