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
 

Re: Metatables

Previous Thread :: Next Thread 
IamAwesome777 is not online. IamAwesome777
Joined: 18 Jul 2011
Total Posts: 2640
22 Dec 2012 11:52 PM
Can someone please explain metatables? I find the wiki hard to understand.
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
23 Dec 2012 12:43 AM
Maybe sometime tomorrow.
Pop me a message so I don't forget. :D
Report Abuse
crazyman32 is not online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
23 Dec 2012 12:44 AM
I could, but I don't want to. Because it's 1:45am and I need sleep.
Report Abuse
IamAwesome777 is not online. IamAwesome777
Joined: 18 Jul 2011
Total Posts: 2640
23 Dec 2012 12:54 AM
:D Thanks
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
23 Dec 2012 01:03 AM
I could and I ACTUALLY TALK TO YOU so we can have a CONNECTION but whatever...Go with AFF because he's santa... BE LIKE THAT!
Report Abuse
crazytomato4 is not online. crazytomato4
Joined: 09 Feb 2011
Total Posts: 1368
23 Dec 2012 01:18 AM
2 AM YEEEAAAAH

SO YOU GOT THESE TABLES

AND WHEN YOU DO STUFF TO THE TABLES, THINGS HAPPEN. LIKE WHEN YOU DO THIS:

TABLE[INDEX] = STUFF

YOU ADD A VALUE TO THE TABLE. SO WITH METATABLES, YOU GET TO CHANGE WHAT HAPPENS WHEN YOU DO STUFF TO THE TABLE. YOU ALSO GET TO MAKE TABLES DO STUFF THAT THEY WOULDN'T NORMALLY BE ABLE TO DO. WITH METATABLES YOU CAN ADD TABLES TOGETHER, YOU CAN CALL A TABLE LIKE A FUNCTION, ETC.

SO YOU HAVE THE LIST OF METAMETHODS ON THE WIKI. THOSE ARE THE THINGS THAT YOU CAN PUT IN YOUR METATABLE TO CHANGE HOW THE TABLE ACTS. USE __CALL AS AN EXAMPLE:

META = {
__call = function(SELF, ...) -- ... = THE ARGUMENTS
print("MAH BOY")
end
}
TABLE = {"HI"}
--SET META AS TABLE'S METATABLE BECAUSE I DONT WANNA
TABLE() -- OUTPUTS: MAH BOY

YOU CAN ALSO STORE OTHER STUFF IN THE METATABLE JUST FOR FUN

META = {__call = function() --[[STUFF]] end, 42, 12212012, 24, 25}
--ASSUME TABLE AND ALL THAT STUFF

COOL THING ABOUT THAT: WHEN YOU DO THAT, YOU CAN INTERATE THROUGH A TABLE WITHOUT SEEING THOSE VALUES:

for I, V in next, TABLE do
print(I,V)
end

BUT YOU STILL HAVE A WAY TO GET THE VALUES USING THE TABLE BY CALLING GETMETATABLE :D

ALSO, YOU CAN USE __index AS A TABLE INSTEAD OF A FUNCTION. ISNT IT AWESOME?

META = {__index = {["POTATO"] = "YEEEEAAAAHHHH"}}
--ASSUME TABLE ETC
print(TABLE["POTATO"]) -- NOTE THAT TABLE["POTATO"] DOESNT ACTUALLY EXIST, STILL OUTPUTS: YEEEEAAAAHHHH

SO WHEN THE TABLE IS INDEXED WITH SOMETHING THAT DOESN'T EXIST, IT WILL SEARCH IN THE __INDEX TABLE FOR THE VALUE.

LAST THING: THE __metatable METAMETHOD LETS YOU USE HIDE THE METATABLE, SO IF YOU TRY TO USE GETMETATABLE, IT WON'T WORK RIGHT

META = {__metatable = "HI"}
--ASSUME STUFF
print(getmetatable(TABLE)) -- OUTPUTS: HI (AS OPPOSED TO THE ACTUAL METATABLE)

SO THATS HOW METATABLES WORK

NOTE THAT I HAVENT USED THESE IN MANY MONTHS AND HAVENT LOOKED AT THE WIKI AT ALL TO WRITE THIS AND ITS 2 AM, SO I MAY BE WRONG ON SOME OF THIS STUFF.

CAPS LOCK IS CRUISE CONTROL FOR COOOOOOOOOOOOOOOOOL

/PLS DONT BAN ME FOR SPAM
Report Abuse
adark is not online. adark
Joined: 13 Jan 2008
Total Posts: 6412
23 Dec 2012 01:51 AM
Obligatory wiki article:

http://wiki.roblox.com/index.php/Metatables
Report Abuse
IamAwesome777 is not online. IamAwesome777
Joined: 18 Jul 2011
Total Posts: 2640
23 Dec 2012 01:54 AM
"I find the wiki hard to understand."
Report Abuse
adark is not online. adark
Joined: 13 Jan 2008
Total Posts: 6412
23 Dec 2012 02:00 AM
Then read it until it makes sense.

If you think something makes absolutely no sense, report it to a wiki writer and try to get it fixed.
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