Jump to content

Timer?


Recommended Posts

Posted (edited)
 

 public boolean isFletching() {
  boolean isFletching = false;
  Timer timer = new Timer(1800, null);
  while (timer.isRunning() && !isFletching) {
   isFletching = myPlayer().getAnimation() != -1 ? true : isFletching;
  }
  return isFletching;
 }
 
 public boolean isStringing() {
  boolean isStringing = false;
  Timer timer = new Timer(1200, null);
  while (timer.isRunning() && !isStringing) {
   isStringing = myPlayer().getAnimation() != -1 ? true : isStringing;
  }
  return isStringing;
 }


 

These doesnt work can you tell me what im doing wrong?.

Edited by Assnerd
Posted (edited)

Don't use while loops in osbot please.

Here's my secret. Create a timer. Set it to 0. Check the time passed. Before your fletching method. (Select knife and log). Do a animation check if true reset the timer.

Then do a else if statements after. Check the timer and see if it passed like 4 secs. Then you would use your fletching method

Edited by Joseph
  • Like 1
Posted

Don't use while loops in osbot please.

Here's my secret. Create a timer. Set it to 0. Check the time passed. Before your fletching method. (Select knife and log). Do a animation check if true reset the timer.

Then do a else if statements after. Check the timer and see if it passed like 4 secs. Then you would use your fletching method

 

Can I ask why while loops are bad? I understand that some may become infinite loops, is there another reason?

Posted

Don't use while loops in osbot please.

Here's my secret. Create a timer. Set it to 0. Check the time passed. Before your fletching method. (Select knife and log). Do a animation check if true reset the timer.

Then do a else if statements after. Check the timer and see if it passed like 4 secs. Then you would use your fletching method

Could you give me an example (code) ? im still learning :E

 

thanks in advance

Posted (edited)

Can I ask why while loops are bad? I understand that some may become infinite loops, is there another reason?

 

You can use them, but make sure to properly break out of them.

Getting a user stuck for 8 hours because a while loop didn't break properly is pretty annoying biggrin.png

 

I didn't even use 1 while loop in all of my scripts smile.png

Could you give me an example (code) ? im still learning :E

 

thanks in advance

 

Basicly this: (I'm using my own timer class though, not sure how osbots timer work)

Timer animationTimer = new Timer(0);

public void fletch(){
   if (script.myPlayer().isAnimating())
      animationTimer.reset();

   if (animationTimer.getElapsed() > 2000) { //time between animations
      //start fletching
   }else{
      //we are fletching
   }
}

Khaleesi

Edited by Khaleesi
  • Like 1
Posted (edited)

You can use them, but make sure to properly break out of them.

Getting a user stuck for 8 hours because a while loop didn't break properly is pretty annoying biggrin.png

 

I didn't even use 1 while loop in all of my scripts smile.png

 

Basicly this: (I'm using my own timer class though, not sure how osbots timer work)

Timer animationTimer = new Timer(0);

public void fletch(){
   if (script.myPlayer().isAnimating())
      animationTimer.reset();

   if (animationTimer.getElapsed() > 2000) { //time between animations
      //start fletching
   }else{
      //we are fletching
   }
}

Khaleesi

thx

 

Edited by Assnerd
Posted

Don't use while loops in osbot please.

Here's my secret. Create a timer. Set it to 0. Check the time passed. Before your fletching method. (Select knife and log). Do a animation check if true reset the timer.

Then do a else if statements after. Check the timer and see if it passed like 4 secs. Then you would use your fletching method

u made my day l0l

  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...