|
| 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
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 15 May 2014 09:46 PM |
| What part do you need help on? |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
| |
|
|
| 15 May 2014 10:35 PM |
| I would but... people drown puppies if the mother can't feed them. D:... |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 26 Aug 2009 |
| Total Posts: 1414 |
|
|
| 15 May 2014 11:48 PM |
oh shoot, uh how would I fix that?
|
|
|
| Report Abuse |
|
|
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
|
  |
| 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 |
|
|
| |
|
|
| 18 May 2014 01:15 AM |
In all practicality, metatables are generally useless for any Roblox project. However, they are VERY fun. |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|