I'm trying to create a runnable that will test to see if you're dead (health below 1) and if you are dead, then it will stop the runnable. If you aren't it will keep going. But I can't find a way to stop the runnable. Is there any way to stop the runnable within the runnable with a script?
Note that the runnable is being run through a thread:
Thread thread1 = new Thread(runnableName);
thread1.start();
Runnable Example:
Runnable r1 = new Runnable() {
public void run() {
while (true) {
if (health < 1) {
// How do i stop the runnable?
}
}
}
}
You can break the loop if health < 1:
if (health < 1) {
break;
}
Or you can change the while condition:
while (health > 1) {
}
while (true) {
if (health < 1) {
// How do i stop the runnable?
return;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With