How to extract the first decimal number from a timer?

troynalltroynall Member Posts: 15
edited February 2014 in Working with GS (Mac)
what would be the easiest way to just EXTRACT the TENTHs place value from the timer ?
Example,
1.08 = 0
1.14 = 1
1.26 = 2
1.95 = 9

Comments

  • SocksSocks London, UK.Member Posts: 12,822
    edited February 2014
    1.26

    1.26*10 = 12.6

    floor(12.6) = 12

    12/10 = 1.2 [save this into an attribute - let's call it "X"]

    floor(1.2) = 1 [save this into another attribute - let's call it "Y"]




    X-Y= the 'tenths place value'

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited February 2014

    Hi @troynall

    And here it is, slightly differently (although very similar to @Socks version): a real attribute to hold your number called TempNum, and an integer attribute, let's call it FirstDec

    So for the following example, FirstDec is set to 0 and TempNum to 1.95 --or whatever the current number is.

    --------------

    Change Attribute FirstDec to TempNum
    Change Attribute TempNum to (TempNum-FirstDec)*10
    Change Attribute FirstDec to floor(TempNum)

    Display Text FirstDec

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

  • SocksSocks London, UK.Member Posts: 12,822
    @gyroscope

    Yep ! That's a lot neater ! :)>-
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited February 2014
    @Socks
    @gyroscope

    mod(floor(number*10),10)

    Example:
    mod(floor(1.26*10),10) = 2

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

  • SocksSocks London, UK.Member Posts: 12,822
    @Socks
    @gyroscope

    mod(floor(number*10),10)

    Example:
    mod(floor(1.26*10),10) = 2
    Damn ! : ) That's tight !
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited February 2014
    @Socks
    @gyroscope

    mod(floor(number*10),10)

    Example:
    mod(floor(1.26*10),10) = 2
    Damn ! : ) That's tight !
    Ha! Ditto, @Socks; good one, @tatiang; you get the biscuit! :-) B-)

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

  • troynalltroynall Member Posts: 15
    @socks - yes it is "tighter", but yours shows more manual mechanics on "how to". And i don't mind doing it your way. I was hung up on the leading digit. But your way was the approx version I wrote in pseudo code. Just trying to wrap my head around all these functions. In a few other languages, All I would do is save the time as a string and then pick my string apart until I get my results.

    Thanks guys. :)
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    The current nightly build available to Pro members contains string manipulation functions that I believe would allow you to do that, though I haven't tried yet.

    Eventually, those features will make their way into the stable build available to everyone.

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

Sign In or Register to comment.