User Tag List

Results 1 to 3 of 3

Thread: [Request] Random Intervals Object

  1. #1
    Clicker Fusion 2.5

    Join Date
    Feb 2014
    1 Post(s)
    0 Thread(s)

    Lightbulb [Request] Random Intervals Object

    While working on a game, I came up with an idea for an extension which I think could be pretty useful to a lot of Fusion users.

    The game I'm working on has a lot of randomly generated elements. Say, for example, that the player opens a treasure chest. The contents of the chest would then be determined from a list of items with associated values, where the values represent the probability of the contents being the item:

    [Chest Contents/Chance]
    Minor Healing Potion=700
    Nearly Useless Weapon=700
    Nearly Useless Armor=700
    Major Healing Potion=300
    Regular Weapon=300
    Regular Armor=300
    The Holy Grail=1

    I then use an INI object to generate two lists, which will determine the interval that a randomly generated number will be tested against:

    [Chest Contents/RandomInterval Low]
    Minor Healing Potion=1
    Nearly Useless Weapon=701
    Nearly Useless Armor=1401
    Major Healing Potion=2101
    Regular Weapon=2401
    Regular Armor=2701
    The Holy Grail=3001

    [Chest Contents/RandomInterval High]
    Minor Healing Potion=700
    Nearly Useless Weapon=1400
    Nearly Useless Armor=2100
    Major Healing Potion=2400
    Regular Weapon=2700
    Regular Armor=3000
    The Holy Grail=3001

    I then use a FastLoop to test a random number in the range of 1 to 3001 against the different intervals. Now, I think it would be very convenient if there were an extension (maybe called the Random Intervals Object or RandomList Object, or something like that), with an internal list that you could add the items with values to. Using an expression, "Get Random Item", would then make the object generate a random number in the range between 1 and the sum of all its contents, automatically test it against the intervals, and return the name of the item associated to the interval as a string.

    Some of its Actions could be:
    Clear List
    Add Item to List
    Delete Item from List

    Some of the expressions could be:
    Get Random Item
    Get Associated Value of Item
    Get % Chance of Item (would return an Item's value divided with the sum of all the items' values, multiplied with 100 - the chance of the item being returned in percent.)
    Get Sum of all Item Values

    This is just an idea, and perhaps there's already an extension somewhere out there that does this. If anybody knows of such an extension, or any other method of doing this that would be simpler than the one described above, please let me know!

  2. #2
    Clickteam Clickteam
    LB's Avatar
    Join Date
    Jun 2007
    Richardson, Texas, North America
    2 Post(s)
    0 Thread(s)
    There doesn't really need to be an extension for this, as the math is trivial enough and you seem to be slightly overcomplicating things.

    The chance of an item is its value divided by the sum of all values - this gets you a number between 0 and 1. Then all you have to do is generate a random real number between 0 and 1 (e.g. with a random number generation object) and select an item whose range covers the random value. Think of it like this:

    Item A
    Item B
    Item C
    Chance (0..1)
    [0.0, 0.5)
    [0.5, 0.7)
    [0.7, 1.0)
    Random Number = 0.533
    Random Number = 0.0
    Random Number = 0.99
    Random Number = 0.75

    All you need is a list of the start values of the ranges and then just go down the list until the random number is greater than or equal to the start value of the range. You could use e.g. the array object to calculate the start values of the ranges from the data in the INI file.
    Working as fast as I can on Fusion 3

  3. #3
    Clicker Fusion 2.5

    Join Date
    Feb 2014
    1 Post(s)
    0 Thread(s)
    You're right, my method was hopelessly overcomplicated in comparison. I set up an Internal List object using the method you described, which I now use universally in my game for every situation requiring a random item to be generated. Thank you!

Similar Threads

  1. Random Object Question
    By mr_mercury06uk in forum Fusion 2.5
    Replies: 4
    Last Post: 19th March 2014, 03:47 PM
  2. Random object spawning random y set x
    By Armiferamortalis in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 23rd December 2013, 11:47 AM
  3. Random object help
    By den333 in forum Multimedia Fusion 2 - Technical Support
    Replies: 8
    Last Post: 4th March 2010, 11:57 AM
  4. Firing at random intervals
    By DarkArchonLord in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 29th May 2009, 06:27 PM
  5. [Request] Random Path
    By onewingedangel in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 15th July 2008, 06:52 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