User Tag List

Results 1 to 7 of 7

Thread: Processing Array Values with a Loop

  1. #1
    Clicker Multimedia Fusion 2
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)

    Join Date
    Dec 2016
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Processing Array Values with a Loop

    I am creating an unlock menu using Active System Boxes and an array. Being new to Fusion I'm struggling to figure out how to achieve the method for the result I'm after.

    The end result should be: Player selects options from 0 to 10 checkboxes and clicks continue (fully working) -> Array is checked and outputs cost for options, player clicks button to apply the options (this is where I struggle) -> Cost is deducted from player and Options are then active (working).

    I currently have it so that each option has a value in the array, 0 = Unselected, 1 = Selected, 2 = Applied. The inital checkboxes toggle the value between 0 and 1. What I'm struggling to figure out is then how to change the value to 2 when the Apply button for the options that have been selected.

    I'm figuring it should be a loop through the array, checking the value and then adding a +1 where the value equals 1.

    So roughly speaking, something like:
    Set array position (0,0);
    Run loop while array y position < 10
    {
    IF (value) EQUALS 1 THEN write value (value)+1 ELSE Do Nothing;
    Set array position (current position)+(y position+1);
    }

    A big part of this is probably me just not knowing where to find, and which functions will achieve this. All and any help would be appreciated!

  2. #2
    Clicker Fusion 2.5 DeveloperHTML5 Export Module

    Join Date
    Jun 2006
    Posts
    1,461
    Mentioned
    10 Post(s)
    Tagged
    0 Thread(s)
    I would create an On Loop "Changes Applied". In here is the code to update the array and change the 1's to 2's would be defined.

    Then with the button object I would set a condition of "When Clicked" and the action .... is to call the Loop "Changes Applied" for just "1" loop.

    This is really just making the loop act like a function or sub procedure.

  3. #3
    Clicker Multimedia Fusion 2
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)

    Join Date
    Dec 2016
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, I hadn't realised you could call a Loop like that, makes a lot of sense.

    Would you (or anybody else) be able to advise how to code the loop using the expressions in fusion? I think running calculations like this on arrays is one area I've really been struggling to figure out. (Alternatively a link to a good tutorial/documentation around this subject?)

    Many thanks!

  4. #4
    Clicker Multimedia Fusion 2
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)

    Join Date
    Dec 2016
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Alright, I've figured out a way to do this, but wanted to check if this is the best way, or if I'm just adding extra events because I'm missing something. For information, I have 6 columns of 10 options that the player can set options from before clicking the apply button. Therefore this needs to check all 10 indexes on the Y, for all 6 indexes on the X, and change the value where it equals 1 to 2, while leaving 0 at 0.

    #Button (Button) clicked
    > (Array.Options) : Set X dimension index 0
    > (Array.Options) : Set Y dimension index 0
    > Start loop "Array Switch X" 6 times

    # On loop "Array Switch X"
    > Start loop "Array Switch Y" 10 times
    > (Array.Options) : Add 1 to X dimension index

    # On loop "Array Switch Y"
    > Start loop "Check Values" 1 times
    > (Array.Options) : Add 1 to Y dimension index

    # On loop "Check Values"
    + Current value( "(Array.Options)" ) = 1
    > (Array.Options) : Write Value current value ( "(Array.Options)" ) + 1 to (index x( "(Array.Options)" ), index y( "(Array.Options)" ))


    Any suggestions if this could be improved, or if there is a fault I haven't noticed. Doing some quick testing it seems to be working as ought.

  5. #5
    Clicker Fusion 2.5 DeveloperHTML5 Export Module

    Join Date
    Jun 2006
    Posts
    1,461
    Mentioned
    10 Post(s)
    Tagged
    0 Thread(s)
    Looks fine ... you have the general idea. You asked if there is a "better" way. Well that just depends...if it meets the need why improve it? If you needed it to work faster you could perhaps use Lua extension and access the MMF array from there but that is more complex to learn.

  6. #6
    Clicker Fusion 2.5Fusion 2.5+ DLC
    casleziro's Avatar
    Join Date
    Mar 2013
    Location
    United States
    Posts
    646
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    That is a decent approach but you can trim things down:

    #Button (Button) clicked
    > Start loop "Array Switch X" 6 times

    # On loop "Array Switch X"
    > Start loop "Array Switch Y" 10 times

    # On loop "Array Switch Y"
    + Current value( "(Array.Options)" ) = 1
    > (Array.Options) : Write Value current value ( "(Array.Options)" ) + 1 to (Loopindex("Array Switch X") ), Loopindex("Array Switch Y"))

  7. #7
    Clicker Fusion 2.5Fusion 2.5+ DLC
    casleziro's Avatar
    Join Date
    Mar 2013
    Location
    United States
    Posts
    646
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Err, instead of checking for "current value" of Array.Options, you would instead check for a value at X,Y, and use Loopindex("Array Switch X") and Loopindex("Array Switch Y") in that third condition. My bad, missed it.

Similar Threads

  1. Save more object in array with loop function part2
    By daniele in forum Multimedia Fusion 2 - Technical Support
    Replies: 14
    Last Post: 16th September 2013, 09:30 PM
  2. Loop rotation with values and acceleration
    By J3sseM in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 25th March 2013, 01:48 PM
  3. BOX2D - Shape Test / BodyID to an array then loop
    By Tuna in forum Hardware Accelerated Runtime
    Replies: 9
    Last Post: 12th April 2010, 11:26 PM
  4. fast loop & array index
    By delusan in forum The Games Factory 2 - Technical Support
    Replies: 2
    Last Post: 19th October 2007, 06:37 PM
  5. Fast loop & array
    By scaneider in forum Multimedia Fusion 2 - Technical Support
    Replies: 12
    Last Post: 12th March 2007, 02:42 PM

Posting Permissions

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