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: Why doesn't this work?

Previous Thread :: Next Thread 
Cyrok is not online. Cyrok
Joined: 11 Jan 2012
Total Posts: 630
16 Jan 2012 08:04 PM
I was working with metatables after reading Anaminus's guide to them, and I ran across this error:

    local myTable = {}
    local myMetatable = {
        __newindex = function(tableName, numberKey, valueType)
            return "The key "..numberKey.." of the table "..tableName.." doesn't hold "..valueType.."!"
        end
    }
    
    setmetatable(myTable, myMetatable)
    print(myMetatable[1])

 > nil

Why does it print nil? What am I doing wrong?

{ Have any broken code that needs fixing? Send me a message and maybe I can assist you. }
Report Abuse
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
16 Jan 2012 08:07 PM
setmetatable(myTable, myMetatable)
should be
setmetatable(myMetatable,myTable)

-[::ƧѡÎḾḠΰῩ::]-[::Maker of stuff and Helper of Scripting::]-
Report Abuse
Cyrok is not online. Cyrok
Joined: 11 Jan 2012
Total Posts: 630
16 Jan 2012 08:14 PM
@swimguy777

I'm not sure if I misunderstood what you said, because I don't see how that makes sense. Doesn't setmetatable() accept two arguments, in the order of the table you metatable will control, and then the metatable itself?

{ Have any broken code that needs fixing? Send me a message and maybe I can assist you. }
Report Abuse
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
16 Jan 2012 08:17 PM
O_o
The wiki says I'm wrong, but I'm almost 100% positive it's worked for me like that before.
Well then...

-[::ƧѡÎḾḠΰῩ::]-[::Maker of stuff and Helper of Scripting::]-
Report Abuse
Cyrok is not online. Cyrok
Joined: 11 Jan 2012
Total Posts: 630
16 Jan 2012 08:23 PM
table your* metatable will control

{ Have any broken code that needs fixing? Send me a message and maybe I can assist you. }
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