You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
A Function That Sums All Arguments
What is the issue? Include screenshots / videos if possible!
I don’t know how to do it
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Do tests
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
function AddFunction(...)
local BeforeIndex = nil
local Args = {...}
local Result = 0
for i,v in pairs(Args)
BeforeIndex = Args[i-1]
Result += BeforeIndex + v
end
return Result
end
Then I thought that if it was at index 1, BeforeIndex would be null because it would be looking for index 0 and it doesn’t exist
then I thought of AfterIndex
function AddFunction(...)
local AfterIndex = nil
local Args = {...}
local Result = 0
for i,v in pairs(Args)
AfterIndex = Args[i+1]
Result += BeforeIndex + v
end
return Result
end
but then I thought that if it was in the final index I would look for the final index +1 and it does not exist and it would be null
function AddFunction(...)
local BeforeIndex = nil
local Args = {...}
local Result = 0
for i,v in pairs(Args)
local SubtractIndex = 1
if Result == 0 then
SubtractIndex = 0
end
BeforeIndex = Args[i - SubtractIndex]
Result += BeforeIndex + v
end
return Result
end
I was a tiny bit confused when reading so this might work