|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|