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 » Scripters
Home Search
 

Re: Applying arithmetic to table values

Previous Thread :: Next Thread 
ascensio is not online. ascensio
Joined: 03 Aug 2013
Total Posts: 498
15 Aug 2015 10:53 PM
I'm glad the enticing title worked. How do I apply (the same) arithmetic to every value in a table? For example, add one to each value.
Report Abuse
hetebro is not online. hetebro
Joined: 29 Apr 2012
Total Posts: 3708
15 Aug 2015 10:54 PM
There might be an easier way, but I'd loop through the table and just edit each value through the loop.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
15 Aug 2015 10:56 PM
But you can do it "cleanly" with metatables.

local numArray = {0, 5, 10, 15};
setmetatable(numArray, {
__add = function(self, value)
local new = {};
for key = 1, #self do
new[key] = self[key] + value;
end
return new;
end;
});

print(table.concat(numArray + 5, ", "));
Report Abuse
lupine is not online. lupine
Joined: 24 Jun 2008
Total Posts: 3561
15 Aug 2015 11:01 PM
Pff, "cleanly". We're savages here, do this instead

local nums = {0, 2, 4, 8, 16, 32}
for i,v in pairs(nums) do
v = v * 2
end
Report Abuse
ascensio is not online. ascensio
Joined: 03 Aug 2013
Total Posts: 498
15 Aug 2015 11:09 PM
them's arrays
but thank you
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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