Help With My function

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

A Function That Sums All Arguments

  1. What is the issue? Include screenshots / videos if possible!

I don’t know how to do it

  1. 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

Anyone Give Me Any Idea To Do This?

Wouldn’t you add just the values and not the indexes?

You can just do this:

local function sumArgs(...)
	local result = 0
	for _, v in pairs({...}) do
		result += v
	end
	return result
end
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

oh yea this is much smaller

local function AddFunction(Table)
	local result = 0
	for _, v in pairs(Table) do
		result += v
	end
	return result
end

keep it the same function name tho

1 Like

this is an excuse to attract attention what i really want to do is this

Really

function Ands(...)



end

Print(Ands(true,true,false)) -- false
function Ands(...)
    local Table = {...}
    if table.find(Table, false) then
        return false
    else
        return true
    end
end

Print(Ands(true, true, false)) -- false

:man_facepalming::man_facepalming::man_facepalming::man_facepalming::man_facepalming::man_facepalming::man_facepalming::man_facepalming::man_facepalming::man_facepalming::man_facepalming::man_facepalming::man_facepalming::man_facepalming::man_facepalming::man_facepalming::man_facepalming::man_facepalming: to me

I am confused…You cannot add boolean values as if they are numerical. If this is not what you mean, please explain further and more concisely.

What do you mean? You can just state your problem in the original post, it even has a higher chance of being answered…

Please don’t be immature and explain your problem properly.

they were facepalming because they didn’t release they could do what I sent them