Pyditn Posted February 3, 2015 Share Posted February 3, 2015 Can someone please tell me a good way to do a timer that starts when the game starts and ends if a object is touched? I tryed many things but it doesnt worked. Thanks for your Answeres! Quote Link to comment Share on other sites More sharing options...
f13rce Posted February 3, 2015 Share Posted February 3, 2015 You will need Time::GetCurrent() for this. This returns the time the application has been running for in milliseconds. You basically keep a variable with the time of when it's started, and constantly check if the Current time minus the start time (so the elapsed time) is bigger or equal than the requirement. Code would look like this: float fStartTime = 0; float fRequiredTime = 5000; // in milliseconds bool bStartChecking = false; void OnCollision(){ fStartTime = (float)Leadwerks::Time::GetCurrent(); // Have to convert from long long to float bStartChecking = true; } void Update(){ if (bStartChecking){ if ((float)Leadwerks::Time::GetCurrent() - fStartTime >= fRequiredTime){ // Do stuff when time has ended } } } Quote Using Leadwerks Professional Edition (Beta), mainly using C++. Windows 10 / Linux Mint, Visual Studio 2017. GPU: NVidia GeForce GTX970, CPU: Intel i7 7700K @ 4.20 GHz Previously known as Evayr. Link to comment Share on other sites More sharing options...
thehankinator Posted February 3, 2015 Share Posted February 3, 2015 In the code below self.time_elapsed will contain the time in milliseconds from application start to when the item touched: Script.time_elapsed = -1 function Script:Collision(entity, position, normal, speed) if self.time_elapsed == -1 then self.time_elapsed = Time:GetCurrent() end end Quote Link to comment Share on other sites More sharing options...
Rick Posted February 3, 2015 Share Posted February 3, 2015 http://www.leadwerks.com/werkspace/files/file/502-timer/ In the collision just call the Stop function on the timer. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.