User Tag List

Results 1 to 10 of 10

Thread: Best way to spread random values to alterable values with no duplicates?

  1. #1
    Clicker 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)
    Bree's Avatar
    Join Date
    May 2014
    Posts
    313
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Best way to spread random values to alterable values with no duplicates?

    Hello! Hoping to get some help with some math questions.

    So I'm trying to figure out how and what the best way I can accomplish this.

    I have 5 values and I want to send those values randomly (with no duplicates) to 5 objects and store them in their first alterable value. So for example this would be how a random setup would look like at the start of frame:

    1 - Alterable Value A, Object 2
    2 - Alterable Value A, Object 5
    3 - Alterable Value A, Object 1
    4 - Alterable Value A, Object 3
    5 - Alterable Value A, Object 4

    If I simply do Random(1-5) then some of the objects might get the same number as the other ones. The objects need to have their own unique number.

    How can I make sure the next object won't get the same number as one that was already selected? I thought maybe I could make a list and start out with 12345 on the first line. Then I could delete a number after one was assigned, but I couldn't figure out how to choose 1 value and delete it. I've only got as far as picking a random number from the list. Maybe that's not the best way to do it though or I'm overthinking it >.<.

    Thanks so much for any ideas or feedback!

  2. #2
    Forum Moderator Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleSWF Export ModuleXNA Export Module
    ProdigyX's Avatar
    Join Date
    Jan 2011
    Posts
    1,197
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Off the top of my head, you could run a loop that iterates through every object and sets this variable if it hasn't already been set.

    Lets assume there are 10 instances of the object and all of their Alterable Variable A's are 0. Then the code might look like this

    Code:
    + Upon Pressing "Enter"
    - Run loop "MainIterationLoop" 10 times
    Code:
    + On Loop "MainIterationLoop"
    - Run loop "SetVariableRandom" -1 times(This continues the loop until you manually stop it. As explained below, this ensures the loop does not stop until an object that has not been assigned a number has been picked)
    Code:
    + On loop "SetVariableRandom"
    + Pick Random Instance of Object
    + If Alterable Variable A of Object = 0
    - Set Alterable Variable A of Object to LoopIndex("MainIterationLoop") + 1
    - Stop Loop "SetVariableRandom"

    So basically what we are doing is that we have a number (LoopIndex("MainIterationLoop") + 1) and we are picking random objects. If this object is not already assigned a number, we assign this object the given number. We then proceed to the next number (by stopping the "SetVariableRandom" loop) and continue this process until all the objects have been chosen.

    If you are unfamiliar with fastloops, this method may be a bit overwhelming but it'll definitely assign a unique random number to every instance of Object.
    ---------------------Update---------------------------------------
    Schrodinger's method, listed immediately below, below is far more succinct and works similar, if not better, to the method I outlined in this post.

  3. #3
    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)
    If values are subsequent numbers
    (like 1-5 in your example)

    I would try this:

    on triggering event
    >>> start loop "set_random_value" 5 times

    on loop "set_random_value"
    +alterable value A of object= 0
    +pick one of (object) (this will pick one object at random)
    >>> set alt.val. A to loopindex("set_random_value") +1

  4. #4
    Clicker Fusion 2.5 DeveloperAndroid Export Module
    Chrille's Avatar
    Join Date
    Jul 2006
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hehe, there's actually a thread on randomizing values without duplicates just a few lines down

    http://community.clickteam.com/threads/96153-Five-Random-But-Different-Numbers-Out-of-72

  5. #5
    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)
    We're storming on math (logic) questions like bees on honey

  6. #6
    Clicker Fusion 2.5 DeveloperAndroid Export Module
    Chrille's Avatar
    Join Date
    Jul 2006
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Beats getting no answers at all :P

  7. #7
    Forum Moderator Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleSWF Export ModuleXNA Export Module
    ProdigyX's Avatar
    Join Date
    Jan 2011
    Posts
    1,197
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Alternatively, you can use the Spread Value function. This will give instances of an object incremental values from a starting value. If you spread value 4 for example, Instance #1 gets 4, Instance #2 gets 5, Instance #3 gets 6, etc... resulting in a unique value for each object instance.

    That being said, if Instance #1 gets x, Instance #2 will always gets x + 1, Instance #3 will always gets x + 2, etc... which means that the values aren't exactly random. You might be able to manipulate this by changing the layer order of the object instances right before you do the spread value action, but it gets messy.

  8. #8
    Clicker 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)
    Bree's Avatar
    Join Date
    May 2014
    Posts
    313
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Thank you!

    Wow so many answers! Thank you so much guys! I was able to get it to work great!!

    I uploaded the MFA so if anyone wants to see a visual of how it works, hopefully will be helpful to the next searcher out there.
    Attached files Attached files

  9. #9
    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)
    Just as an additional moderately useful note

    if you don't want to use the "pick random objects in a zone" (so to not define a zone if you don't need to)

    you can simply use "pick or count" inside the object's own submenu ("group good" qualifier in the example)

    >> Pick "group good" at random
    (will create a "pick one of" condition, that is --> pick one at random)


    Glad you sorted & thanks for sharing btw!

  10. #10
    Clicker 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)
    Bree's Avatar
    Join Date
    May 2014
    Posts
    313
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Ohh, that is very useful actually! Didn't even notice you could pick from the object submenu .

Similar Threads

  1. Replies: 17
    Last Post: 6th January 2016, 11:40 PM
  2. Global Values & Alterable Values with same names
    By Gustav in forum Multimedia Fusion 2 - Technical Support
    Replies: 8
    Last Post: 7th November 2012, 07:15 PM
  3. Get sum of alterable values across duplicates
    By Simon in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 26th March 2009, 02:51 PM
  4. Display values on screen from Alterable Values
    By mikeh in forum The Games Factory 2 - Technical Support
    Replies: 2
    Last Post: 13th May 2008, 02:59 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
  •