I am still working with lists/arrays and i have a question, i want to add all the items in the list what i mean is if i have an array like so: {3,2,3,1,3} the output should be 12 how would i do this?
✓ ANSWER ACCEPTED
How to add all the items in a list together?
2 answers
✓ Accepted answer
this should workd:
total = 0
array = {3,2,3,1,3}
for _,n in ipairs(array) do
total+=n
end
This works for me when i have to get the sum
Add = {1, 2, 3, 4}
local sum = 0
table.foreach(Add, function(i, v)
sum = sum + v
end)
print(sum)
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
*I don't have any code for this