February 9, 20169 yr 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.
February 9, 20169 yr 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; }
February 9, 20169 yr You check for consequences of that action (experience increase, item mutation, player flags, etc...).
February 9, 20169 yr Author 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.
February 9, 20169 yr 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
February 9, 20169 yr 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, 20169 yr by Tom
February 9, 20169 yr 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); }
February 9, 20169 yr It was just a simple example for OP, don't shoot me Edited February 9, 20169 yr by lisabe96
February 9, 20169 yr It was just a simple example for OP, don't shoot me You already dead by prev people xD let me poke you?
February 9, 20169 yr 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, 20169 yr by Explv
February 9, 20169 yr 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.
Create an account or sign in to comment