Making a boolean true for x seconds when condition is met, then reverting it to false
boolean, java
Solution
private long lastTrueTime;
private boolean timedBoolean() {
long now= System.currentTimeMillis();
if(/*condition to set boolean true*/){
lastTrueTime=now;
return true;
}
if (lastTrueTime+3000<now)
return false;
return true;
}
Problem
I'm making a `boolean` so if a certain condition is met, it will return true for 3 seconds, but after that it will return false again. So it's like ``` private boolean timedBoolean() { if(//condition to set boolean true){ return true; } //if condition isn't met for 3 seconds return false; } ``` Been thinking about this for an hour now. Researched SO before I asked.