3 Digit Custom Score Math Issue

0belisk0belisk PRO Posts: 189
edited February 2013 in Working with GS (Mac)
So instead of using the Display Text for my in-game figures such as score im using the technique featured in the OSTime template, but heres the issue, on a 3 digit score system, i cant figure out how to correctly change the self.image of the 2nd image.

000 (integer values)
..^

for the third digit (hundred) im using constrain self.image to (floor(( game.Score )/100))..".png"

for the first digit (1-9) im using constrain self.image to (( game.Score )%10)..".png"

And i have the second digit working correctly up to 099, but once we get into the hundreds, i have the math confused.

How do i get the second digit (tenth) to display correctly when dealing with a 3 digit number system, so for example if the player is on 357 score, what equation would i require for the 5 to display a 5 as it should?

Basically, using the number 357, input an equation to divide it down to 5 so it changes to 5.png, and of course be generic to any number from 100-999 so it will correctly divide itself down to its appropriate number.png

Thanks in advance!

EDIT:

The closest i have gotten so far is by doing constrain self.image to (floor(( game.Score )%100)/10))..".png"

Which for example turned 357 into 5.7, which is close but it needs to be 5, as 5.7.png is invalid.

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited February 2013
    floor((357%100)/10)=5

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

  • 0belisk0belisk PRO Posts: 189
    floor((357%100)/10)=5
    That is the equation i have already worked out and tried, which yields a result of 5.7, not 5... xD
  • 0belisk0belisk PRO Posts: 189
    The only solution i can think of is to make a self.attribute on the 2nd digit actor (integer) value, and constrain the self.image to that instead of the equation, then constrain the self.attribute to the equation which will force it to a interger value, canceling out the .7 on the end of the digit. Ill attempt this idea now, but i would prefer an actual fix! thanks
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    I know it's the formula you came up with but it's also the formula I came up with before I read your whole post. :)

    The floor of any number is a whole number, by definition (http://en.m.wikipedia.org/wiki/Floor_and_ceiling_functions). Why are you getting a decimal?

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

  • 0belisk0belisk PRO Posts: 189
    I know it's the formula you came up with but it's also the formula I came up with before I read your whole post. :)

    The floor of any number is a whole number, by definition (http://en.m.wikipedia.org/wiki/Floor_and_ceiling_functions). Why are you getting a decimal?
    Im not quite sure, i made an actor display the results of the equation as i was confused myself to why it isnt working, and i noticed it yields a decimal, 357 > 5.7.

    the floor(357%100) turns it into 57, then the /10 brings it down to 5.7

    So i tried reversing the ordering, to floor((357)/10)%100)..".png" and then you get 57.

    for now i have just done what i explained in my previous post:

    "The only solution i can think of is to make a self.attribute on the 2nd digit actor (integer) value, and constrain the self.image to that instead of the equation, then constrain the self.attribute to the equation which will force it to a interger value, canceling out the .7 on the end of the digit."

    Which is indeed working, but it wasnt my preferred method of fixing it, but i guess ill be happy to keep this, unless you're able to shed some light :P
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Okay, I see the problem in your formula. You have the /10 outside of the floor function. Look carefully at my formula and you'll see that floor() is the outermost function.

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

Sign In or Register to comment.