The Sum of a List

Discussion in 'Skript' started by Spalw, Mar 25, 2020.

  1. Hey guys,

    I've tried to find an answer online but couldn't so I'm posting here.

    I'm trying to get the sum value of all of the integer values in my list variable, is there any way to do this?

    Like set {_test} to the sum of {balances::*}

    I hope that makes sense,
    Thanks for any help.
  2. Thanks for the quick reply.
    I've been working on a project for a while and just totally forgot some basics.

    For anyone searching this in the future,
    I looped the list variable and added the loop-value to a counter and then used that onwards.
    • Agree Agree x 1
  3. For anyone who may need the code.
    Code (Text):

    set {_sum} to 0
    loop {object::*}:
       add loop-value to {_sum}
    broadcast "The sum is %{_sum}%"
  4. Please close the thread if the question has been answered.