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: What is wrong with this?

Previous Thread :: Next Thread 
david1234501 is not online. david1234501
Joined: 04 Oct 2008
Total Posts: 737
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
david1234501 is not online. david1234501
Joined: 04 Oct 2008
Total Posts: 737
13 Feb 2014 01:20 PM
b
Report Abuse
david1234501 is not online. david1234501
Joined: 04 Oct 2008
Total Posts: 737
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
david1234501 is not online. david1234501
Joined: 04 Oct 2008
Total Posts: 737
13 Feb 2014 01:35 PM
bump
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