candyfreak Posted February 9, 2016 Share Posted February 9, 2016 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. Quote Link to comment Share on other sites More sharing options...
lisabe96 Posted February 9, 2016 Share Posted February 9, 2016 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; } Quote Link to comment Share on other sites More sharing options...
Botre Posted February 9, 2016 Share Posted February 9, 2016 You check for consequences of that action (experience increase, item mutation, player flags, etc...). 1 Quote Link to comment Share on other sites More sharing options...
candyfreak Posted February 9, 2016 Author Share Posted February 9, 2016 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. Quote Link to comment Share on other sites More sharing options...
FrostBug Posted February 9, 2016 Share Posted February 9, 2016 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 2 Quote Link to comment Share on other sites More sharing options...
Tom Posted February 9, 2016 Share Posted February 9, 2016 (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 February 9, 2016 by Tom Quote Link to comment Share on other sites More sharing options...
Explv Posted February 9, 2016 Share Posted February 9, 2016 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); } 1 Quote Link to comment Share on other sites More sharing options...
lisabe96 Posted February 9, 2016 Share Posted February 9, 2016 (edited) It was just a simple example for OP, don't shoot me Edited February 9, 2016 by lisabe96 Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted February 9, 2016 Share Posted February 9, 2016 It was just a simple example for OP, don't shoot me You already dead by prev people xD let me poke you? Quote Link to comment Share on other sites More sharing options...
Explv Posted February 9, 2016 Share Posted February 9, 2016 (edited) It was just a simple example for OP, don't shoot me Shoot him! But seriously you do it in your scripts too Edited February 9, 2016 by Explv 1 Quote Link to comment Share on other sites More sharing options...
lisabe96 Posted February 9, 2016 Share Posted February 9, 2016 Shoot him! But seriously you do it in your scripts too In my older script i probably did, but not anymore. Decompile my woodcutting script and you'll see I handle any possible unexpected situations. Quote Link to comment Share on other sites More sharing options...