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: Metatables; I can't figure them out.

Previous Thread :: Next Thread 
Rocketerkid is online. Rocketerkid
Joined: 10 Oct 2011
Total Posts: 1237
15 May 2014 09:19 PM
I love the idea of them, and from what I've seen they are very useful. I've mastered so many things in rbx.lua, but for some reason they are one of the only things I can't even a good enough grasp on to test. I've tried Wiki's and countless things, I just can't get them, would anyone be willing to explain, or help me with them?
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
15 May 2014 09:46 PM
What part do you need help on?
Report Abuse
Rocketerkid is online. Rocketerkid
Joined: 10 Oct 2011
Total Posts: 1237
15 May 2014 10:17 PM
Simply all of it, I've seen some cool uses out of them like it seems like you can use them to see a variable as string or anything. I just don't understand ANY OF IT, and the wiki articles just confuse me more.
Report Abuse
Rocketerkid is online. Rocketerkid
Joined: 10 Oct 2011
Total Posts: 1237
15 May 2014 10:18 PM
All I could tell you is there is setmetatable and getmetatable and you have to use __index for something. o.e
Report Abuse
DaleMaturingan is not online. DaleMaturingan
Joined: 17 Oct 2012
Total Posts: 1179
15 May 2014 10:21 PM
Delete System32
Report Abuse
Rocketerkid is online. Rocketerkid
Joined: 10 Oct 2011
Total Posts: 1237
15 May 2014 10:35 PM
I would but... people drown puppies if the mother can't feed them. D:...
Report Abuse
cooldude999921 is not online. cooldude999921
Joined: 13 Aug 2011
Total Posts: 3702
15 May 2014 10:43 PM
heres a meta table... lol


hi = {}
im_a_metatable = {}


print('Hi')


setmetatable(hi, im_a_metatable)
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
15 May 2014 10:48 PM
No.

Anyway, a metatable basically gives you more control over tables.
setmetatable(tbl, tbl2) sets tbl2 as tbl's metatable (and you can attach metatables to metatables, blah)
Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
15 May 2014 11:19 PM
local meta = setmetatable({},{
__index = function(self,v) --fires when you call 'meta[some index]
--'self' is the table itself (meta) and 'v' is the index that u used: 'meta[this is ur index]'
return self[v]..' is a noob' -- returns the original string (if it's a string) with a new string that has 'is a noob'
end,
})

meta.a = 'john' -- newindex in the metatable
print(meta.a)--the '__index' function is called and returns:
'john is a noob'
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
15 May 2014 11:25 PM
"meta.a = 'john' -- newindex in the metatable
print(meta.a)--the '__index' function is called and returns:
'john is a noob'"

The __index metamethod only is invoked if self[key] is nil. And doing what you did will cause an overflow.
Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
15 May 2014 11:48 PM
oh shoot, uh how would I fix that?

Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
15 May 2014 11:50 PM
local x = setmetatable({},{
__index = function(self, key)
return key ..' is a noob';
end;
});

print(x.John);
>'John is a noob'
Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
16 May 2014 12:23 AM
OHHHHHHHHHHhh~~~ lewlelwlel
No wonder why my meta's never worked -__-
Report Abuse
DaleMaturingan is not online. DaleMaturingan
Joined: 17 Oct 2012
Total Posts: 1179
18 May 2014 12:40 AM
Delete_System_32
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
18 May 2014 01:15 AM
In all practicality, metatables are generally useless for any Roblox project.
However, they are VERY fun.
Report Abuse
RbxUtility is not online. RbxUtility
Joined: 15 May 2014
Total Posts: 138
18 May 2014 02:07 AM
Rocketerkid the main way to think of metatables is how the name implies the tables to act- on a deeper functional level than they would otherwise being a normal table.

When using metatables its really nothing complicated, your just creating a sort of procedural functionality for the table to abide by and with that you can tell the functionality what to do in case of an event like a variable in the table is changed, referenced, or the table is being used in a mathematical equation. to put it quite simply, when the table is being used and the table has a metatable and the user is trying to do something outside the functional parameters of the table, the script will look at the metatable and try to find a procedural code to execute for the modification the user is making, or referencing.
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