Jump to content

Timer?


Acerd

Recommended Posts

 

 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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

  • Recently Browsing   0 members

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