Time Remaining: String Formatting

0 favourites
  • 6 posts
From the Asset Store
Time rewind like in "Braid". Choose objects that will be affected by time rewind
  • I made a little counter for time remaining to level ends in my game. I can't upload it now, but the example consists only in:

    1. Add a Text on layout;

    2. Add a global variable like "secondsToPlay" and set a number of seconds, for example 150 for 2 minutes and a half, or 120 to 2 minutes on Event Sheet;

    3. Add Event: System > Every 1 second(s);

    • 3.1. Add Action > Text > "Time Remaining: " & Floor(secondsToPlay/60) & ":" & Floor(secondsToPlay%60)
    • 3.2. Add Action > System > Subtract 1 from secondsToPlay;

    The counter will start: 2:0 - 1:59 - 1:58 - ... - 1:9 - n

    The problem is: As you can see, I don't know how I can put a zero left on numbers to have this visual representation: 02:00 - 01:59 - 01:58 - ... - 01:09 - n.

    In programming languages, for example, we can format the outputed string like: print "Missiles: %02" % numberOfMissiles and obtain a plain text like: "Missiles: 003".

    From now on, the question is obvious: "How can I do this with Construct 2?", how can I format my string? Or... if anyone has a better way to do this...

    Thanks in advance.

  • time<10 ?"0"&time :time

    Probably a few other ways as well.

  • C2 has the ZeroPad function? If so, use ZeroPad(secondsToPlay,2)

  • well

    right("00"&seconds,2)

    works fine (:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you, about the ZeroPad function, returns a error on r75: "Unknow Expression 'ZeroPad'", but the "right" function works well.

  • Very good information for the formatting of time. You just do not know this automatically. I used it in an educational game where students have to set an analog clock and it syncs and displays in a digital clock and it works perfectly.

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