Jump to content

How to determine when an action is completed.


Recommended Posts

Posted

What is the most reliable way to ensure that an action is completed before starting another one.

 

I know their is sleep methods but is this truly the best way to ensure you give enough time for an event to happen before another one starts ?

 

An example is perfectly fine as a answer to this question and if my question seems unclear just let me know.

 

Thanks in advance.

 

 

Posted

Totally depends on what action mate.

Like for a death npc you could check the hitpoints, for woodcutting you could check if the tree still exists and if the bot is animating...

Or for banking you'd check if it's open.

 

Example situation:

onLoop() {
switch (state) {
  case OPEN_BANK:
    banker.interact("Bank");
    state = State.BANK;
    break;

  case BANK:
    if (!getBank().isOpen()) { //if bank is not open
      break; //wait
    } //else
    //Dostuff
    break;
}
return 600;
}
Posted

 

Totally depends on what action mate.

Like for a death npc you could check the hitpoints, for woodcutting you could check if the tree still exists and if the bot is animating...

Or for banking you'd check if it's open.

 

Example situation:

onLoop() {
switch (state) {
  case OPEN_BANK:
    banker.interact("Bank");
    state = State.BANK;
    break;

  case BANK:
    if (!getBank().isOpen()) { //if bank is not open
      break; //wait
    } //else
    //Dostuff
    break;
}
return 600;
}

 

 

You check for consequences of that action (experience increase, item mutation, player flags, etc...).

 

Thanks, That's all that i needed, I figured that was the way to do it. Was just making sure their wasn't an easier way.

Posted

 

Totally depends on what action mate.

Like for a death npc you could check the hitpoints, for woodcutting you could check if the tree still exists and if the bot is animating...

Or for banking you'd check if it's open.

 

Example situation:

onLoop() {
switch (state) {
  case OPEN_BANK:
    banker.interact("Bank");
    state = State.BANK;
    break;

  case BANK:
    if (!getBank().isOpen()) { //if bank is not open
      break; //wait
    } //else
    //Dostuff
    break;
}
return 600;
}

 

That looks extremely unsafe. Bank opening failure = permanent stuck

 

  • Like 2
Posted (edited)

 

Totally depends on what action mate.

Like for a death npc you could check the hitpoints, for woodcutting you could check if the tree still exists and if the bot is animating...

Or for banking you'd check if it's open.

 

Example situation:

onLoop() {
switch (state) {
  case OPEN_BANK:
    banker.interact("Bank");
    state = State.BANK;
    break;
  case BANK:
    if (!getBank().isOpen()) { //if bank is not open
      break; //wait
    } //else
    //Dostuff
    break;
}
return 600;
}

 

Let me fix that for you

onLoop() {
switch (state) {
  case OPEN_BANK:
   if(!getBank().isOpen()){
     if(banker.interact("Bank")){
        state = State.BANK;
     }
   }
     break;
 case BANK:
    if(getBank().isOpen()){
       bank stuff
    }
    break;
}
return 600;
}
Edited by Tom
Posted

 

Totally depends on what action mate.

Like for a death npc you could check the hitpoints, for woodcutting you could check if the tree still exists and if the bot is animating...

Or for banking you'd check if it's open.

 

Example situation:

onLoop() {
switch (state) {
  case OPEN_BANK:
    banker.interact("Bank");
    state = State.BANK;
    break;

  case BANK:
    if (!getBank().isOpen()) { //if bank is not open
      break; //wait
    } //else
    //Dostuff
    break;
}
return 600;
}

 

Your states should be based on some boolean condition, not set when you think they should be. Otherwise when an action fails your script will be rekt.

Also you should use the getBank().open() method.

enum State{ OPEN_BANK, BANK }

private State getState(){

    return getBank() != null && getBank().isOpen() ? State.BANK : State.OPEN_BANK;
}

@Override
public int onLoop() throws InterruptedException{
    switch (getState()) {
        case OPEN_BANK:
            getBank().open();
            break;

        case BANK:
            //Dostuff
            break;
    }
    return random(200, 250);
}
  • 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...