User Tag List

Page 2 of 2 FirstFirst 1 2
Results 11 to 18 of 18

Thread: Quick Question about "Mod" operator

  1. #11
    Clicker Multimedia Fusion 2
    dragonguy's Avatar
    Join Date
    Apr 2008
    Location
    RULE BRITANNIA!
    Posts
    3,071
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Quick Question about "Mod" operator

    Try abs(negative number)

  2. #12
    Clicker Multimedia Fusion 2 DeveloperSWF Export Module

    Join Date
    Jun 2006
    Posts
    6,773
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Re: Quick Question about "Mod" operator

    Try abs(negative number)
    What?

  3. #13
    Clicker Multimedia Fusion 2
    dragonguy's Avatar
    Join Date
    Apr 2008
    Location
    RULE BRITANNIA!
    Posts
    3,071
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Quick Question about "Mod" operator

    Thats how to get it to work with negative numbers.

  4. #14
    No Products Registered

    Join Date
    Jan 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Quick Question about "Mod" operator

    Thanks, although I'll still probably never use it since I have no programming skills, it's useful to know what it is just in case. And thanks for the examples.

  5. #15
    Clicker Multimedia Fusion 2 Developer

    Join Date
    Jun 2006
    Location
    Darlington, UK
    Posts
    3,298
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Quick Question about "Mod" operator

    Quote Originally Posted by dragonguy
    Try abs(negative number)
    Thats how to get it to work with negative numbers.
    Actually no. abs(-2) is 2, when you'd expect it to be 30 using mod. Think directions: 0 = 32, -1 = 31, -2 = 30...

  6. #16
    No Products Registered

    Join Date
    Jun 2006
    Location
    Land of raging rockets
    Posts
    1,231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Quick Question about "Mod" operator

    Try abs(negative number)
    *ignore*
    I think it does, but like this:
    -128 / 60 = -2
    -128 mod 60 = -8

    To wrap it positive IIRC you do this:
    ((number mod limit) + limit) mod limit)
    Indeed. I don't find it very practical though. I've seen implementations where -128 mod 60 is 52. I find it rather annoying to have to write it the complicated way all the time, but then I guess I'm just lazy.

    According to wikipedia there are three common ways to implement modulo. I suppose then it's down to luck which one you get with your development environment..

  7. #17
    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)

    Re: Quick Question about "Mod" operator

    Euclidean definition ftw! I wish MMF2 used this.

  8. #18
    Clicker Fusion 2.5 Developer

    Join Date
    Jul 2008
    Location
    UK
    Posts
    1,393
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)

    Re: Quick Question about "Mod" operator

    The mod function has heaps of uses - here's a couple more...

    To determine if a number is odd or even:
    if "Number" mod 2 = 0, then "Number" is even
    if "Number" mod 2 = 1, then "Number" is odd


    To find the difference between two angles:
    ((Angle1 - Angle2 + 540) mod 360) - 180

    It essentially tells you whether to rotate clockwise or counter-clockwise, depending on whether the result is positive or negative.


    To load a tile-based map from an array, using a fast loop:
    XPosition = LoopIndex(">Fastloop<") mod DimX( ">Array<" )
    YPosition = LoopIndex(">Fastloop<") / DimX( ">Array<" )

Page 2 of 2 FirstFirst 1 2

Similar Threads

  1. "Cannot load joystick2.mfx" when "Compress the runtime" unchecked. Fine when checked.
    By DistantJ in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 14th September 2013, 09:44 PM
  2. Quick "ForEach" question
    By alspal in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 20th April 2012, 03:22 PM
  3. "Bug" For Saving and Loading Frame Positions AND "Timer Glitch"?
    By Zarpo in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 27th March 2012, 12:40 PM
  4. Quick Time object & "User clicks..." problem
    By kikiriki in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 13th December 2010, 11:05 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
  •