User Tag List

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14

Thread: Sum of Alterable Values

  1. #1
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleXNA Export Module

    Join Date
    Aug 2011
    Location
    Beverly Hills, CA USA
    Posts
    506
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sum of Alterable Values

    I would like to get the Sum of all Alterable Value Bs for a particular object. What is the easiest way to do this?

  2. #2
    Clicker Fusion 2.5 DeveloperiOS Export Module
    ChrisBurrows's Avatar
    Join Date
    May 2011
    Location
    Tasmania, Australia
    Posts
    622
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The best way is to spread an ID value into another alterable value, say A for each of the objects. Then run a loop as many times as there are objects. Using the loopIndex function and with only one line of code you can make it so that on loop 1 the alterable value B of the object with ID value 1 is added to a counter , on loop 2 the alterable value B of the object with ID value 2 is added to a counter and so on.

    Let me know if you need an example.

  3. #3
    Clicker Multimedia Fusion 2 DeveloperiOS Export ModuleSWF Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)
    King_Cool's Avatar
    Join Date
    Aug 2008
    Posts
    2,335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    - Give your Object a new value called Index_ or ID_ or somthing similar
    - At some point ( before you want to sum up the values ) use 'spread value 0' in Objects Index_ to give each Object a unique identifier
    - Now you can run a 'fast loop' ( you should run it 'number of Object' times ) and compare the fast loops 'Index' value to the Objects Index_ value to retrive each Objects value B
    ...
    The ForEach extencion will also do the trick, with slightly less effort

  4. #4
    Clicker Fusion 2.5 DeveloperiOS Export Module
    ChrisBurrows's Avatar
    Join Date
    May 2011
    Location
    Tasmania, Australia
    Posts
    622
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    That's what I said.

    Here's an example for if you are new to fast loops or just don't have any idea what we are talking about.

    http://www.whenthereisnoroominhellth.../addvalues.mfa

  5. #5
    Clicker Multimedia Fusion 2 DeveloperSWF Export Module
    RickyRombo's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere between here and there
    Posts
    3,167
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What I would do is use the ForEach object, as King_Cool mentioned, and loop through each object and add the sum to a value/counter.

  6. #6
    Clicker Fusion 2.5 DeveloperiOS Export Module
    ChrisBurrows's Avatar
    Join Date
    May 2011
    Location
    Tasmania, Australia
    Posts
    622
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Why use the ForEach object? Fast loops work fine.

  7. #7
    Clicker Fusion 2.5 MacFusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleXNA Export ModuleUnicode Add-on
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Fusion 2.5+ DLC (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    Phi's Avatar
    Join Date
    Jan 2010
    Location
    England
    Posts
    1,822
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    ForEach is designed for object selection, and its tests proved faster than fast-loops.

  8. #8
    Clicker Fusion 2.5 DeveloperiOS Export Module
    ChrisBurrows's Avatar
    Join Date
    May 2011
    Location
    Tasmania, Australia
    Posts
    622
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Oh really? I haven't used it before. I try to avoid using extensions if I can help it.

    Did you check out my example? In 3 lines of code it added up all Alterable B values. I refined it now down to 2 lines. Click the same link if you want to see. How many lines for the ForEach extension? Also, unless you are adding a very large amount of object values together I can't imagine speed between the 2 methods noticeable in any way.

    I'll be happily prove wrong.

  9. #9
    Clicker Multimedia Fusion 2 DeveloperiOS Export Module
    Nifflas's Avatar
    Join Date
    Jul 2006
    Posts
    2,613
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, let's say you have 10 active objects and you want to loop through them with a fastloop. When this happens the "on loop" action will trigger 10 times and each time there'll be 10 value comparasions (one for each object) to filter out all but the correct object for this loopindex. That's 100 comparasions. If you have 50 objects, there'll be 2500 comparasions. For 100 objects, 10000 comparasions. It gets exponentially slower the more objects you add.

    Sure, looping through objects with fastloops work for very simple operations, but for more demanding operations, or just games where you iterate through objects a lot, the ForEach object is absolutely essential.

    In every game since Knytt Stories, the slowness of fastloops have been a problem for me, in Saira it's the main CPU eater of the entire game. Then, the ForEach game came along, and my new Knytt game wouldn't even work without it.

  10. #10
    Clicker Fusion 2.5 DeveloperiOS Export Module
    ChrisBurrows's Avatar
    Join Date
    May 2011
    Location
    Tasmania, Australia
    Posts
    622
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    That's good to know. I'm working on a pretty big project at the moment but I am yet to notice a decrease in speed from using fastloops (and I use a lot) but when I do I know what to use instead. Cheers.

Page 1 of 2 1 2 LastLast

Similar Threads

  1. Global Values & Alterable Values with same names
    By Gustav in forum Multimedia Fusion 2 - Technical Support
    Replies: 8
    Last Post: 7th November 2012, 06:15 PM
  2. Alterable Strings as Alterable Values?
    By King_Cool in forum Multimedia Fusion 2 - Technical Support
    Replies: 9
    Last Post: 27th March 2012, 07:14 PM
  3. Display values on screen from Alterable Values
    By mikeh in forum The Games Factory 2 - Technical Support
    Replies: 2
    Last Post: 13th May 2008, 01:59 PM
  4. Alterable Strings and Alterable Values limit :(
    By Pedro Almeida in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 13th October 2006, 06:38 AM

Posting Permissions

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