Dakota99
|
  |
| Joined: 30 Aug 2007 |
| Total Posts: 11628 |
|
|
| 02 Apr 2014 12:29 AM |
wiki.roblox.com/index.php?title=Metatable
So you want to print hello world whenever you change something in a table? Well, too bad, because obviously you're not smart en--
~ setmetatable(a,b) UH OH, THIS IS PRETTY COMPLEX, RIGHT? Wrong. ] function hi(t,i,v) print("Hello world!") rawset(t,i,v) end ] ] Metatable={__newindex=hi} ] Table={} ] setmetatable(Table,Metatable) ] Table[1]="hi" -> Hello World!
In short, __newindex(table,index,value) is changed to hi(table,index,value). Then, the value is set, and Hello World is printed, because the function was called.
Bam. Metatables. Callbacks. 30 seconds. Done.
------------------------------------------------------------------------------ randomsig: now 50% off for never | twitter.com/sScriptis | RandomString: BFctp |
|
|
| Report Abuse |
|
Goulstem
|
  |
| Joined: 04 Jul 2012 |
| Total Posts: 7177 |
|
| |
wazap
|
  |
| Joined: 29 Jun 2007 |
| Total Posts: 23234 |
|
|
| 02 Apr 2014 02:05 AM |
Simpler explanation:
Its pretty much an Event for a table
analogous to
.Touched .Chatted
without the need for :connect() |
|
|
| Report Abuse |
|