User Tag List

Results 1 to 4 of 4

Thread: Correct expression for random direction event

  1. #1
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export Module
    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)
    Wodjanoi's Avatar
    Join Date
    Jun 2015
    Location
    Germany
    Posts
    665
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)

    Correct expression for random direction event

    Let's say a player object shoots bullets in the current direction of the player object and I want a 25 percent chance that the shooting direction changes from the current direction to current direction -1 or current direction +1?

    Set direction("bullet") to dir("player object")

  2. #2
    Clicker Fusion 2.5 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)
    Sumo's Avatar
    Join Date
    Jul 2008
    Posts
    642
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Correct expression for random direction event

    Before your shooting code, add a new line of code above. When you click, you set a counter or alterable value to Random(4). You can set any of the numbers (0-3) to be the trigger for your 25% value.

    An easy way to randomize set values is to use a list object. You fill the list object with your options, so -1 or 1. Then you can do get Line random(total number of lines) to pick a random value from your selected pool.

    Then add a new condition in your shooting code. Test to see if that alterable value or counter equals your value you're testing, say 0. Then set the bullet direction to your players current direction+get Line random(total number of lines).

    You would have to copy your shooting line code and make sure when the value doesn't equal 0, then it just shoots normally.

    There's a bunch of ways to do this probably, but this is one of the easier ways.


    Sent from my iPhone using Tapatalk

  3. #3
    Clicker 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)
    Volnaiskra's Avatar
    Join Date
    Jan 2014
    Location
    www.sprykegame.com
    Posts
    2,558
    Mentioned
    133 Post(s)
    Tagged
    0 Thread(s)
    you can do it within one action this way:



    The random number (from -4 to 4) will be quartered and rounded down into an integer (because direction only accepts integers), so everything other than 4 or -4 will end up producing 0

    Technically, this probably doesn't produce a 25% chance (2 out of 8) but something like a 22.222% chance (2 out of 9). rrandom(-4,4) produces 9 possibilities (-4, -3, -2, -1, 0, 1, 2, 3, 4) and 2 of them (-4 and 4) produce a change of direction. If you want exactly 25%, there'll definitely be a way - just fiddle with the algebra a bit.

  4. #4
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export Module
    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)
    Wodjanoi's Avatar
    Join Date
    Jun 2015
    Location
    Germany
    Posts
    665
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)
    I came to the same solution yesterday, but I decided to stay away from the 25% chance, because it wasn't
    really necessary for the desired result as I thought first.
    Thanks a lot for the detailed explanation Volnaiskra! Actually I was a bit confused that I got it working using the direction values in the random expression like this.

Similar Threads

  1. The correct way to write a random timer
    By DrWho in forum Fusion 2.5
    Replies: 1
    Last Post: 24th August 2016, 12:46 AM
  2. Need help with Random() expression
    By Filip in forum Fusion 2.5
    Replies: 2
    Last Post: 26th June 2016, 07:24 PM
  3. Replies: 38
    Last Post: 1st October 2015, 10:33 PM
  4. Expression problem for random text
    By Drekko in forum The Games Factory 2 - Technical Support
    Replies: 1
    Last Post: 17th November 2011, 04:51 PM
  5. What correct expression Image's center Xpos/Ypos
    By BackStaged in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 10th September 2010, 05:00 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
  •