Jump to content

How to determine when an action is completed.


candyfreak

Recommended Posts

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.

 

 

Link to comment
Share on other sites

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

 

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.

Link to comment
Share on other sites

 

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

 

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

 

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
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...