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 » Scripters
Home Search
 

What is a metatable?

Previous Thread :: Next Thread 
WolfgangVonPrinz is not online. WolfgangVonPrinz
Joined: 24 Oct 2013
Total Posts: 4656
30 Jul 2015 10:15 AM
Ik what a table is, and how to use them, but I've heard of metatables and I checked the wiki, and still was like dafuq?
Help please?

Women are like fine wine, I can't get their tops off
Report Abuse
QuintinityZero is not online. QuintinityZero
Joined: 01 Oct 2008
Total Posts: 10618
30 Jul 2015 10:17 AM
Basically, you can use them to manipulate the behavior of tables. Metatables contain metamethods that fire when a certain action is done to the table and this can be used to override the action or do anything else.
Report Abuse
QuintinityZero is not online. QuintinityZero
Joined: 01 Oct 2008
Total Posts: 10618
30 Jul 2015 10:21 AM
A quick example:

local tab = {}; -- our normal table
local mt = { -- our metatable
__call = (function(t, ...)
print(...);
end),

__index = (function(tab, key)
return 0;
end),
};

setmetatable(tab, mt); -- apply the metatable to our 'tab' table

The __call metamethod allows you to call the table as a function and in this call will print the arguments.

tab("hi", 1) --> hi 1

The __index metamethod fires when a key is indexed that doesn't exist. In this case, we return 0 instead of nil.

print(tab.x) --> 0

It prints 0 even though tab.x does not exist.
Report Abuse
WolfgangVonPrinz is not online. WolfgangVonPrinz
Joined: 24 Oct 2013
Total Posts: 4656
30 Jul 2015 10:22 AM
Ah alright. I understand it now. Thanks

Women are like fine wine, I can't get their tops off
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
30 Jul 2015 10:28 AM
That siggy...

I still don't have a practical use for metatables. But, I should be using it in my new project, Energiser Engine (please check it out!). :P

Enjoying your stay at the Scripters Forum? Join this! http://www.roblox.com/My/Groups.aspx?gid=2582784
Report Abuse
QuintinityZero is not online. QuintinityZero
Joined: 01 Oct 2008
Total Posts: 10618
30 Jul 2015 10:30 AM
I used them in Nettables (tables that are automatically synchronized among all clients).

So when you make a change like tab.x = 1, it updates the 'tab' table among all clients.
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
30 Jul 2015 10:34 AM
?

Who edits it, the client or the server?
We have ModuleScripts as well... :P

Enjoying your stay at the Scripters Forum? Join this! http://www.roblox.com/My/Groups.aspx?gid=2582784
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
30 Jul 2015 10:35 AM
Wait, screw what I said about ModuleScripts. :P
(I said that since I'm thinking of ModuleScripts a lot for my engine). :P

Enjoying your stay at the Scripters Forum? Join this! http://www.roblox.com/My/Groups.aspx?gid=2582784
Report Abuse
QuintinityZero is not online. QuintinityZero
Joined: 01 Oct 2008
Total Posts: 10618
30 Jul 2015 10:41 AM
The server modifies it and it automatically gets updated on all clients. It is also locked so clients cannot modify it at all.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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