Imthabawse Posted March 22, 2019 Share Posted March 22, 2019 Made a simple clay miner that mines clay and banks. Running into issues in the onLoop() when using else if's and else. To me when I read it, it makes sense to me but the bot just sits there. When I remove else if's and else works fine. Confused Any suggestions ? Code I have now: import org.osbot.rs07.api.map.Area; import org.osbot.rs07.api.model.RS2Object; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.utility.ConditionalSleep; @ScriptManifest(name = "Clay", logo = "", version = 1, author = "Imthabawse", info = "Mines clay and banks") public class Clay extends Script { private Area bankArea = new Area(3185, 3437, 3184, 3436); private Area clayArea = new Area(3179, 3370, 3181, 3372); private void bank() { RS2Object bankbooth = getObjects().closest("Bank booth"); if (bankbooth != null) { bankbooth.interact("Bank"); log("Banking.."); new ConditionalSleep(2500) { @Override public boolean condition() { return bank.isOpen(); } }.sleep(); } if (bank.isOpen()) { bank.depositAll(); log("Depositing clay.."); } } private void mineClay() { RS2Object clay = getObjects().closest(7454, 7487); if (!myPlayer().isAnimating()) { if (!getInventory().isFull()) if (clay != null) { clay.interact("Mine"); log("Mining clay.."); new ConditionalSleep(2500) { @Override public boolean condition() { return clay.exists() && !getInventory().isFull(); } }.sleep(); } } } @Override public int onLoop() { if (clayArea.contains(myPlayer())) { mineClay(); } if (!clayArea.contains(myPlayer())) { * had an else if here getWalking().webWalk(clayArea); mineClay(); *had an else here } if (getInventory().isFull()) { if (bankArea.contains(myPlayer())) { bank(); } if (!bankArea.contains(myPlayer())) { *had an else if here getWalking().webWalk(bankArea); bank(); } } return 1500; } } Quote Link to comment Share on other sites More sharing options...
HeyImJamie Posted March 22, 2019 Share Posted March 22, 2019 (edited) I'm not quite sure what your question is haha. Assuming you want it to be neater? The reason your else if's weren't working is likely due to how you had your code ordered. In regards to neatening it, why not simplify it a little? if (Inventory.isFull()){ // we can't mine, so bank bank(); } else { // all good, we can mine mine(); } private void bank() { // bank code } private void mine() { if !area.contains(player) { walk to the area! } else { we can mine, put mine code here } } There's obviously much nicer ways than this, but this would be a good starting point for you Edited March 22, 2019 by HeyImJamie 1 Quote Link to comment Share on other sites More sharing options...
Imthabawse Posted March 22, 2019 Author Share Posted March 22, 2019 @HeyImJamie my question was why the else if's and else wasn't working the way it should (well in my head anyway :P) You cleared that up for me though lol so thanks. Quote Link to comment Share on other sites More sharing options...
Imthabawse Posted March 22, 2019 Author Share Posted March 22, 2019 Also realizing a path would be ideal in this situation since it's an A to B scenario. Webwalker like's to take some wild paths sometimes lol. Quote Link to comment Share on other sites More sharing options...
Imthabawse Posted March 22, 2019 Author Share Posted March 22, 2019 @HeyImJamie Implemented you're suggestion into another project simple iron miner. Thanks again for the feedback! Code: private void bank() { if (Banks.VARROCK_EAST.contains(myPlayer())) { RS2Object banker = getObjects().closest("Bank booth"); log("In bank.. getting closest banker."); if (banker != null) { banker.interact("Bank"); log("Banking.."); new ConditionalSleep(2000) { @Override public boolean condition() { return bank.isOpen() && getInventory().isEmpty(); } }.sleep(); } if (bank.isOpen()) { bank.depositAll(); } } else { if (!Banks.VARROCK_EAST.contains(myPlayer())) { getWalking().webWalk(Banks.VARROCK_EAST); log("Not in bank.. walking there."); } } } private void mineIron() { if (ironArea.contains(myPlayer())) { if (!myPlayer().isAnimating()) { if (!myPlayer().isMoving()) { if (!getInventory().isFull()) { RS2Object ironore = getObjects().closest(7488); log("Getting closest iron ore."); if (ironore != null) { ironore.interact("Mine"); log("Mining.."); new ConditionalSleep(2000) { @Override public boolean condition() { return ironore.exists() && !myPlayer().isAnimating(); } }.sleep(); } } } } }else{ if(!ironArea.contains(myPlayer())) { getWalking().webWalk(ironArea); log("Walking to mining area.."); } } } @Override public int onLoop() { if(getInventory().isFull()) { bank(); }else{ mineIron(); } return 1500; } } Quote Link to comment Share on other sites More sharing options...
HeyImJamie Posted March 22, 2019 Share Posted March 22, 2019 Awesome! Now I'd suggest you start looking at other things, such as better checks on the booleans available to you, and maybe neatening it even more? For example: You can use && to check for multiple conditions in one line! Quote Link to comment Share on other sites More sharing options...
Imthabawse Posted March 22, 2019 Author Share Posted March 22, 2019 3 minutes ago, HeyImJamie said: Awesome! Now I'd suggest you start looking at other things, such as better checks on the booleans available to you, and maybe neatening it even more? For example: You can use && to check for multiple conditions in one line! Yes I know about the && (and) just like to write it out if's{ the first time cause I'm weird. Quote Link to comment Share on other sites More sharing options...
Script Kid Posted March 22, 2019 Share Posted March 22, 2019 3 hours ago, Imthabawse said: my question was why the else if's and else wasn't working the way it should (well in my head anyway :P) I recreated your code based on your comments @Override public int onLoop() { if (clayArea.contains(myPlayer())) { } else if (!clayArea.contains(myPlayer())) { } else { this will never be executed } return 1500; } You can either be in the area or not. There is no third option, so the last else block will never get executed. 1 Quote Link to comment Share on other sites More sharing options...
Imthabawse Posted March 22, 2019 Author Share Posted March 22, 2019 @Script Kid Thanks for the feedback! 1 Quote Link to comment Share on other sites More sharing options...