How do I display decimals in a text field (ie. timer)

0 favourites
  • 8 posts
From the Asset Store
A very simple to set up ZElevation based depth of field system for your game. Fully commented.
  • Hi there, i found this thread which seemed promising but also a bit confusing..

    all that said my game has a timer.. with a NUMBER variable called "Timer".. let's say you have 4 seconds to do something.. i would need it to start at 4.0 and always show a decimal.. 3.8 3.7... 3.1 3.0 2.9 etc

    it seems like there must be some way to just get in there and be able to round a variable like my "Timer" variable to drop off anything after a certain decimal.

    Thanks!

    Caleb

  • The thread definitely talks about what I'm looking for, but i just don't follow the expressions he's using as they don't (to me) seem to really correspond to how you would work in an event sheet.

    all of the formatted string stuff was confusing.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • You could use tokenat and left expression but I don't know if it would be the best option since it will run every tick.

    example(if your timer is a number, use str to convert to string):

    tokenat(timer, 0, ",")&","&lef((tokenat(timer,1,","), 2)

    The first tokenat should retrieve the integer numbers and the second should get two numbers after the comma

    Example: timer = 4,37079798734234

    Would return 4,37

    I didn't tested it on c2 but should work.

    edit: https://www.scirra.com/manual/126/system-expressions

    Edit: How are you doing this timer?

    I think it would be an option doing this way too.

    Every 0.01 seconds > add 0.01 to timer (timer as a number)

    This way you don't need to do anything and never would return more than 2 numbers after the comma.

  • how does that work exactly? making something into a string in C2? do i need to make a new variable to put the converted value or is it done in the expression itself?

    using your expression i got a syntax issue.. i think "lef" is meant to be left but still something in there wasn't working right.

    you use the "," throughout the formula which would be a period right for a timer right?

    This looks really promising I've just never had to work with casting values from a number to string or the other way around so the whole concept inside of C2 and the right way to do it is a bit mysterious to me.

  • how does that work exactly? making something into a string in C2? do i need to make a new variable to put the converted value or is it done in the expression itself?

    using your expression i got a syntax issue.. i think "lef" is meant to be left but still something in there wasn't working right.

    you use the "," throughout the formula which would be a period right for a timer right?

    This looks really promising I've just never had to work with casting values from a number to string or the other way around so the whole concept inside of C2 and the right way to do it is a bit mysterious to me.

    Yes, it is left. I typed wrong.

    Well, you can use it. https://www.scirra.com/tutorials/678/in ... -functions

    It's simple and work.

  • oh that's nice. That's an awesome tutorial. this is exactly what i needed. a working example capx to emulate and then some! thanks!

  • I've been trying this out more and the example they give is good as a timer going up, but i'm struggling trying to figure out how to get a seoncds and decimal to appear as it should..

    this is the closest I've gotten so far

    zeropad(floor(Timer% 60), 1) & "." & zeropad(floor(Timer%60), 1)

    however this results in showing the timer value like this.. 5.5 4.4 3.3 I can't figure out how to shift the area to the right of the period to display the value in the .0 area..

    i'm trying to make it count down 4.0 3.9 3.8 3.7 etc.. I'm sure its just a few simple changes but as i dug deeper into this tuturial it was clear they were not going to discuss how to get in to milliseconds..

    it seems like it might have something to do with changing the % value, but i've tried a bunch of variations and nothing seems to allow me to grab the milliseconds of the timer (or even the time value from the tutorial)

    Thank you again for your help with this!

  • Hey I found this thread also which is even closer to what i want.. well pretty much spot on.. but it just shows a VERY different approach to the structure. always interesting to see how different people approach things

    I'm dissecting that capx next to take that approach.. i was able to quickly modify it to make the action subtract from and changed the timer from 0 to 10 and it counted down nicely.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)