|
| 13 Feb 2014 01:19 PM |
So I'm trying to use a metatable to add everyone's income together. It should be returning 15, but it isn't. I'm pretty new to metatables, if you couldn't tell. Also, this isn't using Roblox Lua, but it is pretty much the same thing.
numbers = {John.income = 5, David.income = 10}
setmetatable(numbers, { __index = function(self, key) if key:lower() == "totalincome" then local sum = 0 for _, v in pairs(self) do sum = sum + v.income end print(sum) end end })
local run = numbers.totalincome io.read() |
|
|
| Report Abuse |
|
| |
|
| 13 Feb 2014 01:28 PM |
If it makes it easier to read, this is the script formatted correctly:
http://pastebin[DOT]com/WyDC5zuD |
|
|
| Report Abuse |
|
| |