Interpolating Integers

I have two attributes, one attribute that stores a certain value, and another that interpolates towards that number. They're both integer attributes, but when the interpolator interpolates to the value, I'm getting a bunch of decimals when it does so until it reaches the value. Does anyone know why it does that and/or how to fix it? Thank you!

Having trouble with your game? Sounds like a personal problem.

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    This is how interpolate behaves. If you want only integer intermediate values, you can either floor()* the attribute or you can use something like Timer every 0.1 seconds change attribute game.integer to game.integer+1.

    *or ceil() or prec()

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • SocksSocks London, UK.Member Posts: 12,822
    edited February 2014
    I have two attributes, one attribute that stores a certain value, and another that interpolates towards that number. They're both integer attributes, but when the interpolator interpolates to the value, I'm getting a bunch of decimals when it does so until it reaches the value. Does anyone know why it does that and/or how to fix it? Thank you!
    I think people confuse the way attributes work in this regard, the type of attribute (real, integer . . . etc) just describes the 'storage method', not the thing being stored.

    So it's perfectly possible to store the number 3 as an integer attribute but still extract it and - for example - chop it in half to get 1.5 (a non-integer number), the fact that it was *stored* as an integer doesn't impart some quality to the number that it carries with it from then onwards.

    Once a number is out of its 'integer' or 'real' or 'angle' shaped storage box it is just a number, for example if we were to pull a number 5 out of each of those different sorts of 'storage boxes' we wouldn't have three different sorts of number 5, they would all just be 5.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    That's actually a very good explanation, @Socks. And it explains why I can display a number as text (it's no longer "an integer") and even why I can use 0 or 1 to represent a boolean value.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • ADSentertainmentADSentertainment Member Posts: 397
    @Socks

    Aaaah, alright, thank you for the explanation!

    Having trouble with your game? Sounds like a personal problem.

  • ADSentertainmentADSentertainment Member Posts: 397
    This is how interpolate behaves. If you want only integer intermediate values, you can either floor()* the attribute or you can use something like Timer every 0.1 seconds change attribute game.integer to game.integer+1.

    *or ceil() or prec()
    What do the functions do actually? I hope I don't sound TOO uneducated asking this xP I'm only a high school student.

    Having trouble with your game? Sounds like a personal problem.

  • SocksSocks London, UK.Member Posts: 12,822
    edited February 2014
    What do the functions do actually?
    They do all sorts of things.

    For instance floor rounds a number down:

    Floor (24.58) = 24
    Floor (1.6) = 1
    Floor (398.22434) = 398
    Floor (17.9) = 17

    etc etc

    'Ceil' rounds a number up:

    Ceil (24.58) = 25
    Ceil (1.6) = 2
    Ceil (398.22434) = 399
    Ceil (17.9) = 18

    'Prec' lets you define how many decimal points you want:

    Prec (398.22434,1) = 398.2
    Prec (398.22434,2) = 398.22
    Prec (398.22434,3) = 398.224
    Prec (398.22434,4) = 398.2243
  • ADSentertainmentADSentertainment Member Posts: 397
    What do the functions do actually?
    They do all sorts of things.

    For instance floor rounds a number down:

    Floor (24.58) = 24
    Floor (1.6) = 1
    Floor (398.22434) = 398
    Floor (17.9) = 17

    etc etc

    'Ceil' rounds a number up:

    Ceil (24.58) = 25
    Ceil (1.6) = 2
    Ceil (398.22434) = 399
    Ceil (17.9) = 18

    'Prec' lets you define how many decimal points you want:

    Prec (398.22434,1) = 398.2
    Prec (398.22434,2) = 398.22
    Prec (398.22434,3) = 398.224
    Prec (398.22434,4) = 398.2243
    Aaaaah, alright! I was actually wondering if they had a function that would show a certain amount of decimal places, thanks!

    Having trouble with your game? Sounds like a personal problem.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Just to add that prec(#,0) rounds a number to the nearest whole number.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Sign In or Register to comment.