Jump to content

Recommended Posts

Posted

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!

Posted

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
 }
}
}

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.

Posted

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

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...