How Do I Sum a List Variable? (without a loop)


#1

1) Give a description of the problem
I want to sum a list of integers but it’s not working.

2) What is the expected behavior?
Added should = 2 after execution.

3) What is happening/not happening?
I’m doing something wrong but I don’t know what… everything I looked up online appears adding a list of numbers should be this simple.

4) Post a Green Snapshot of the pistonimage
Rather than clouding this with the complicated piston I’m trying to get to work - I’ve made this one to demonstrate the idea of what I’m trying to do. Note after execution the Added value was set to zero:


#2

Functions are not aware of lists


#3

I haven’t tested but thinking out loud here:

sum(arrayItem(0,Test), arrayItem(1,Test), arrayItem(2,Test))


#4

Thanks guys!


#5

or sum(Test[0], Test[1], Test[2]) ? :smiley:


#6

Thanks guys, all valid solutions! But not quite as ‘lazy’ as I was looking for, lol.

What I was trying to figure out whether it was possible or not was to have one summing function that I wouldn’t have to update when I added more values to the list/array. That would give my piston the flexibility to expand easily - but I’m beginning to think it’s not possible.


#7

sure you can. here you go:


#8

That’ll work, thanks @bangali!


#9

@bangali is the master when it comes to these for statements