User Tag List

Results 1 to 7 of 7

Thread: Summation of values in an array

  1. #1
    No Products Registered

    Join Date
    Sep 2015
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Summation of values in an array

    Is there an expression to add up all of the values in a column or row of an array without typing out each position individually?

    What I've been doing so far was:
    Set Global Value A
    >ValueAtXY ("Array", 1, 1) + ValueAtXY ("Array", 1, 2) + ValueAtXY ("Array", 1, 3)

    .. And so on. I'm sure there's a shorter way to write that out, am I correct?

  2. #2
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export Module
    Fusion 2.5 (Steam)
    schrodinger's Avatar
    Join Date
    Nov 2014
    Posts
    3,155
    Mentioned
    27 Post(s)
    Tagged
    1 Thread(s)
    Yeah, you should use loops

    on "start sum" condition
    (>>> set Global Value A to 0) if you want to reset the value each time you perform the calculation
    >>> start loop "sum_array" DimY(array) times (since you seem to be summing Y's now, right?)

    on loop "sum_array"
    >>> Set Global Value A to Global Value A + ValueAtXY("Array", 1, loopindex("sum_array"))


    if your array has 1 based index, use loopindex +1

  3. #3
    No Products Registered

    Join Date
    Sep 2015
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well that's pretty cool. To expand on the idea is there a way to exclude a specific position in the array from being included in this loop? E.g. ValueAtXY("Array", 1, 2)?

    Oh and thanks!

  4. #4
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export Module
    Fusion 2.5 (Steam)
    schrodinger's Avatar
    Join Date
    Nov 2014
    Posts
    3,155
    Mentioned
    27 Post(s)
    Tagged
    1 Thread(s)
    thanks for thanking

    if you have to exclude only some specific positions
    I would hard code them in the condition this way:

    on loop "sum_array"
    +loopindex("sum_array") <> number
    >>> Set Global Value A to Global Value A + ValueAtXY("Array", 1, loopindex("sum_array"))

  5. #5
    Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleXNA Export ModuleInstall Creator ProUnicode Add-on

    Join Date
    Jun 2011
    Posts
    628
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    It will be faster if he just use Add ValueAtXY("Array", 1, loopindex("sum_array")) to Global Value A instead of Set global value

  6. #6
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export Module
    Fusion 2.5 (Steam)
    schrodinger's Avatar
    Join Date
    Nov 2014
    Posts
    3,155
    Mentioned
    27 Post(s)
    Tagged
    1 Thread(s)
    you're right, I copy pasted from first post and didn't think of that

  7. #7
    No Products Registered

    Join Date
    Sep 2015
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you both. I'll be able to build on this very easily!

Similar Threads

  1. Count and display values from an array
    By Sewaz in forum Fusion 2.5
    Replies: 4
    Last Post: 28th June 2015, 02:13 AM
  2. Array vs Global Values
    By comrade_yak in forum Fusion 2.5
    Replies: 0
    Last Post: 9th April 2014, 09:41 PM
  3. Summing the values of an array
    By fawfulfan in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 18th July 2012, 07:14 PM
  4. Add values to Array without setting X and Y
    By Boba Fonts in forum Multimedia Fusion 2 - Technical Support
    Replies: 7
    Last Post: 12th March 2012, 11:58 PM
  5. Array vs. Counter vs. Object values
    By alxmrg in forum Hardware Accelerated Runtime
    Replies: 7
    Last Post: 19th May 2010, 10:12 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •