Score over a million...

Hey all,
this has actually been tackled before (I'll provide the link below), but the question has to do with GS numbers. If you go over 999,999, the number will turn into a scientific number, instead of displaying, 1,000,000 etc.
My question is in two parts. For starters, I'm curious if anyone has any unique solutions to this, that may not have been presented before? And/or two, if you look at the linked gs forum solution below, you'll see a demo provided with a solution. But I don't fully understand how that solution works. I'm curious if anyone can explain the logic of how that solution works, so that I'm not merely copying the solution- I'm understanding it. Any help would be appreciated.
Thanks as always!

LINK:
http://forums.gamesalad.com/discussion/43171/display-large-integer

Best Answers

  • RThurmanRThurman Posts: 2,881
    edited January 2013 Accepted Answer
    You might want to try the padInt(x,y) function. It will give you a little more wiggle room (maybe to about 100 million).

    padInt(game.DisplayNumber,10)
  • gyroscopegyroscope I am here.Posts: 6,598
    edited January 2013 Accepted Answer

    Hi @anatomyofdreams , I'm sure @RThurman won't mind me explaining...

    The padInt expression literally pads out the number in the following way: if there are less places in the number than the amount given (in the "y" of the expression) then zeros are added before the number.

    Example: say your integer start value is 21, and you put in a text display behaviour padInt(game.DisplayNumber,2) it will display 21. If you made it padInt(game.DisplayNumber,3) it will display 021, and so on. So for numbers up to 9,999,999, you'd put padInt(game.DisplayNumber,7), and with this example attribute value, it'll show as 0000021.

    The example RT gave - padInt(game.DisplayNumber,10), you'd get 0000000021. hope that's made it a bit clearer for you.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

Answers

  • gamesfuagamesfua Member Posts: 723
    @RThurman is that all i have to do? Im sorry, but if you wouldnt mind, can you explain the logic of how this works and what a padint is? I want to become a stronger coder and understand it, instead of just copy. And where would i put this? Im using a standard integer attribute for my score (for the sake of this example, lets just call that attribute SCORE). Thanks a million!
  • gamesfuagamesfua Member Posts: 723
    @gyroscope and @RThurman you are both incredible! Thank you thank you thank you!!!! Makes perfect sense now! So I could probably say something like if SCORE is greater than 999,999 THEN do the display code you mentioned above. I'm going to give this a shot.
    Really fantastic. Life savers!
    Thanks!
    :)
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Sounds like you're all set, but just thought I'd chime in with an explanation of the demo you mentioned. It basically creates a power of ten counter. Think of when kids learn basic addition:

    ..5+
    ..7
    --
    ..2

    Whoops! We need to "carry the one." That demo just carries the one into a different integer attribute when the number reaches 999,999 and resets the number to 0 again.

    The trick of the DisplayText actor is that it concatenates the counter number (e.g. 1=1 million) with the <1 million number.

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

  • FallacyStudiosFallacyStudios Member Posts: 970
    So I've encountered a similar situation and just wanted a little clarification if I will be able to accomplish this properly.

    In my game the currency I would like to hit approx 99,999,999 as the cap. It would seem I can use the padInt correct? Well how would I go about using it in the image font numbers done just like in Tshirtbooths video.

    Constrain attribute
    self.image = floor((game.money%self.div)/(self.div/10)..".png"

    I tried doing this going up to 99 mill like this but it started displaying some numbers odd so I'm thinking it needs to be done with pad int. So would I simply put in padInt(game.money,10) where the game.money is?

    I also have an actor that governs when it exceeds the 99,999,999 that it takes the extra out and puts it in another actor to pull from when it goes below 99,999,999. Should I be putting a padInt in there as well? It looks like this:

    Rule
    game.money>99,999,999 (no the , isn't there in code)
    Then
    game.excess money to game.excess money+(game.money-99,999,999)
    game.money to 99,999,999

    Rule
    game.money<99,999,999 AND game.excess>0
    Then
    self.Money transfer to 99,999,999-game.money
    game.Money to game.Money+self.Money transfer
    game.excess money to game.excess money - self.money transfer

    I doubt these two rules would need the padInt, but it doesn't hurt to ask. But as far as the Number Images would it need padInt?

    Thanks
  • FallacyStudiosFallacyStudios Member Posts: 970
    Basically after giving the whole padInt thing a shot with the Number images I got the same result as without it. If my money number is 12,345,678 ... it displays as 12,345,700
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited January 2013
    Basically after giving the whole padInt thing a shot with the Number images I got the same result as without it. If my money number is 12,345,678 ... it displays as 12,345,700
    @FallacyStudios Well spotted...it can't be right, can it....I can't see any reason why it's rounding up at the end....this must surely be a bug...unless 6 places is the limit in GSC for this, so that's just the way it is.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • FallacyStudiosFallacyStudios Member Posts: 970
    Poo. I was hoping this would be the perfect fix :(. Wanted my Tycoon game to have numbers relatively close to normal and the only way to accomplish it was to have the numbers extend into the millions. Oh well.

    Btw just curious @gyroscope, do you have any idea what "nan" is? Some how my number once went from displaying text of the number to suddenly displaying "nan". If not no big. Well unless i start encountering it frequently lol.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited January 2013

    Btw just curious @gyroscope, do you have any idea what "nan" is? Some how my number once went from displaying text of the number to suddenly displaying "nan". If not no big. Well unless i start encountering it frequently lol.
    I know for some programming languages, nan or NaN stands for not a number... don't know if that helps at all...(it could be a number you're trying to display, but one that's outside of a particular limit; so the program can't show/represent the number and then puts nan instead).

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • FallacyStudiosFallacyStudios Member Posts: 970
    Yea that must be where I was seeing it from then. Thanks.
  • PhoticsPhotics Member Posts: 4,172
    edited January 2013
    Display Text
    game.score.."000"
Sign In or Register to comment.