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: Metatatable?

Previous Thread :: Next Thread 
ninjaknight101 is not online. ninjaknight101
Joined: 04 Apr 2011
Total Posts: 1281
22 Jun 2012 10:43 AM
This is giving me a weird output. I'm just experimenting with the metatable, and it syas the metatable is locked??? How to fix?


x = {"My ", "Is "} c = {"name ", "Bobby"} setmetatable(x, c) for i = 1, #x do print(getmetatable(x[i])) end

Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
22 Jun 2012 10:56 AM
x = {"My","Is"}
c = {
__index = {"Name","Bobby"}
}
value = setmetatable(x,c)
for i,v in pairs(value) do
print(i,v)
end

I haven't worked with metatables in a bit, but try that.

Also, getmetatable will just get print the table and a bunch of characters.
Report Abuse
ninjaknight101 is not online. ninjaknight101
Joined: 04 Apr 2011
Total Posts: 1281
22 Jun 2012 11:06 AM
Hrrmmm, doesn't work... I just want to make two tables, one with all the names of the players, and the other with their kills. Next sort them and return the winner's name.
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
22 Jun 2012 11:43 AM
You don't need a metatable for that.

People = {kingkiller1000 = 0, ninjaknight101 = 0}
Report Abuse
NXTBoy is not online. NXTBoy
Joined: 25 Aug 2008
Total Posts: 4533
22 Jun 2012 11:48 AM
Try pretending to be the computer here. When `i` is 1, you execute `getmetatable(x[i])`, which is the same as `getmetatable(x[1])` and therefore `getmetatable("My ")`. Getting the metatable of a string was stopped by roblox around a year ago.

Having said that, metatables are not what you want here.
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
22 Jun 2012 12:34 PM
table = {"Hi"}
x = {
__index = {"My","Name","Is","Miz"}
}
value = setmetatable(table,x)
print(value[1])
print(value[2])
print(value[3])
print(value[4])

Printed all.

Probably the only reason it didn't print was because I didn't call the index method by indexing the tables.
Report Abuse
ninjaknight101 is not online. ninjaknight101
Joined: 04 Apr 2011
Total Posts: 1281
22 Jun 2012 02:27 PM
@King, then how do you read the values from the table? Btw Miz, thank you. <:D
Report Abuse
ninjaknight101 is not online. ninjaknight101
Joined: 04 Apr 2011
Total Posts: 1281
22 Jun 2012 02:36 PM
Aha, found a working one in my stuff:

local x = {"I", "to", "Roblox", ", Play", " build", "and", "much", "stuff!"}
local y = {"Like", "program", "Lua", "Baseball,", "robots", "do", "other", "LOL!"}

setmetatable(x, y)

for i = 1, #x do
print(x[i])
local meta = getmetatable(x)
print(meta[i])
end
Report Abuse
TehChikenHater is not online. TehChikenHater
Joined: 11 Jun 2012
Total Posts: 497
22 Jun 2012 02:39 PM
Ninja, two tables.

Players={"TehChikenHater","Player"}
Scores={"TehChikenHater"=1,"Player"=2}
game.Players.PlayerAdded:connect(function(Player)
for i=1,#Players do
if Player.Name=Players[i] then
for n=1,#Scores do
if Player.Name=Scores[i] then
Player.leaderstats.Score=Scores[i]
end
end
end
end
end)

Probably won't work. :P

--TehChikenHater ლ(ಠ_ಠლ)
Report Abuse
ninjaknight101 is not online. ninjaknight101
Joined: 04 Apr 2011
Total Posts: 1281
22 Jun 2012 04:39 PM
I actually love using metatables, I can store all my tables in one place :P, It's just fun to link them together
Report Abuse
NXTBoy is not online. NXTBoy
Joined: 25 Aug 2008
Total Posts: 4533
22 Jun 2012 04:55 PM
This is _NOT_ what metatables are for. No really. Don't do it.
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