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
 

[Tutorial-ish] Metatable Callback Explanation in 30 Seconds

Previous Thread :: Next Thread 
Dakota99 is not online. 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 is not online. Goulstem
Joined: 04 Jul 2012
Total Posts: 7177
02 Apr 2014 12:53 AM
Soooo....?
Report Abuse
wazap is not online. 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
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