|
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 22 Jun 2012 11:43 AM |
You don't need a metatable for that.
People = {kingkiller1000 = 0, ninjaknight101 = 0} |
|
|
| Report Abuse |
|
|
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
|
  |
| 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 |
|
|
|
| 22 Jun 2012 02:27 PM |
| @King, then how do you read the values from the table? Btw Miz, thank you. <:D |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|