User Tag List

Results 1 to 3 of 3

Thread: Forcing decimal value.

  1. #1
    No Products Registered

    Join Date
    Jul 2008
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Forcing decimal value.

    Hi, I have a trouble. I was making a forced platforming game in the past (basically the screen keep scrolling to the right and the game character moves to the right too in the same time, the player loses if the game character gets left behind the screen). Anyway, I uses several codes from the tutorial mode by David N and it has worked perfectly. This is the code.

    Note: Horiz is alterable value of the game character that define its movement to the right

    +Always
    -set Horiz to 2

    +Horiz("character") <> 0
    -Start loop "horiz" Abs(Horiz("character")) times

    +On loop "horiz"
    -set position of the detector at (0,0) from the character
    -set X coordinate to X coordinate of the character + (Horiz("character")/Abs(Horiz("character")))

    +On loop "horiz"
    +character is overlapping a backdrop
    -Stop loop "horiz"
    -Set position of detector at (0,0) from the character
    -set X coordinate to X coordinate of the character + (0-Horiz("character")/Abs(Horiz("character")))
    -set Horiz to 0

    So as you see, the character speed is decided from the first line of the code which is set Horiz to 2.
    Problem is that 2 is too fast for me and 1 is way to slow. I tried to put decimal like 1.5 but for some reason it is rounded down to 1. It seems like any decimal number is rounded down. IS there any way to do this? In beginning I thought the statement Absolute is the one that create this problem, but getting rid of it doesn't seem to fix the problem.

    Thanks again!

  2. #2
    Clicker Multimedia Fusion 2

    Join Date
    Sep 2006
    Location
    Britain, South Coast
    Posts
    1,030
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Forcing decimal value.

    Nah, absolute removes the sign of a number. So it turns -12 and 12 into the same number.

    MMF doesn't let you place an object halfway along a pixel. So it can't physically move 1.5px at a time.

    The best solution is to record the object's location in its alterable values. Go to properties and set up two alterable values. You can name 'em something like:

    "X Pos"
    "Y Pos"

    These are just numbers, so they can hold fractions quite happily. You need to remember to tell MMF that the numbers it's dealing with are fractions, or it'll calculate it with whole numbers (it's a lot quicker).

    So instead of a calculation like '1/2' do '1/2.0' or '1.0/2' - Something to show that you want a precise answer.

    With a variable, do this:
    value("COUNTER") / (value("COUNTER")+0.0)

    Here, we're adding '0.0' to either of the numbers in this equation, which tells MMF that we want a precise answer.

    Anyway, to get your object moving at slower or more precise speeds you simply do this code:


    //Record the starting position in the vars of the object:
    On Start of Frame
    ---- Character: Set "XPOS" value to 'x("CHARACTER")'
    ---- Character: Set "YPOS" value to 'y("CHARACTER")'

    //Now add or subtract from these alterable values:
    //Player will move right at a speed of 0.5px per frame:
    Always
    ---- Character: Set "XPOS" value to 'XPOS("CHARACTER")+0.5'

    //Now move to the positions in xpos and ypos values:
    Always
    ---- Character: Set x position to 'XPOS("CHARACTER")'
    ---- Character: Set y position to 'YPOS("CHARACTER")'

    Voila! Done.

  3. #3
    No Products Registered

    Join Date
    Jul 2008
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Forcing decimal value.

    I figured that is the problem too. Anyway, your code is perfect. It works like a charm now. Thanks!

Similar Threads

  1. Decimal places?
    By ChrisBurrows in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 23rd October 2011, 08:07 PM
  2. Possible for Slope as a decimal?
    By Kid_Roleplay in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 28th December 2010, 01:30 AM
  3. Decimal hell.
    By Vapyrical_Curse in forum Multimedia Fusion 2 - Technical Support
    Replies: 11
    Last Post: 12th September 2010, 02:55 AM
  4. hex to decimal??
    By Gibbon in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 24th June 2009, 03:05 PM
  5. Decimal Number bug
    By Cocodrilo in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 5th April 2008, 12:48 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
  •