Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Help with CopperCube
Timer in CopperCube

dynamogames
Registered User
Quote
2023-03-01 17:26:02

I implemented VP's digital timer in my game. The timer contains milliseconds, seconds, minutes and hours. I have implemented the timer in my game and it works fine but I'm trying to implement a feature where the game records the players best time when the player dies and there would be a 2D overlay which displays the "best time" (something like High Score but in the context of time) or the highest time the player stays alive before dying. For example, if the player plays the game 3 times and records, 1:30, 1:45 and 2:30, I want to record the "2:30" time and save it into variable and display for the player.

I already tried implementing it on my own, but the problem I faced was that the VP digital timer has different variables for Seconds and Minutes, so to save the best time was an issue because of the 2 variables. I'll really like someone to help me on this.

This is the link to the Digital Timer from VP:
https://veganpete.itch.io/reques...


okeoke
Registered User
Quote
2023-03-02 11:23:23

Hi dynamogames,

I think the best way is to convert both minutes and seconds into ms. It's easier to compare since it's just a number and also easier to store for the same reason.

So, I assume you have 2 variables with minutes and seconds as the game completes.
// convert to ms
var ms = minutes * 1000 * 60 + seconds * 1000;

Now you read the current high score value from disk using either a built action or ccbReadFileContent(), and simply compare two numbers. If the new one is higher you re-write the high score.

In order to show the highscore on UI you have to convert ms to minutes:seconds string.
//var ms = your_time_in_ms;
var dateFromMs = new Date(ms);
var formattedString = dateFromMs.getMinutes() + ':' + dateFromMs.getSeconds();
// set overlay text property with formattedString


Hope this helps.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Inter?ational" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact