mrdukesilver Posted February 1, 2022 Share Posted February 1, 2022 (edited) So I have made a very beginner script but it did the job until I wanted to add world hopping. Each time my code is executing, the script doesn't wait for the world hopping to take place, it just opens the world hopping menu and goes to trade once again. I tried adding sleeps too after "worldHop1" but it only made the world hopping take this amount of time and still didn't even hop afterwards, just trades again. I would really appreciate it if someone can help me regarding this! Here is the part of my script that I am talking about: @Override public int onLoop() throws InterruptedException { isReadyToTrade(); trade(); sleep(3000); Buy(); sleep(3000); ExitStore(); sleep(5000); checkInventory(); sleep(3000); worldHop1(); return 0; } public void worldHop1(){ getWorlds().hop(308); } Edited February 1, 2022 by mrdukesilver Quote Link to comment Share on other sites More sharing options...
BravoTaco Posted February 4, 2022 Share Posted February 4, 2022 (edited) @mrdukesilver Without having knowledge of the code inside of the other methods, this will be rather hard to debug. Try executing only the worldHop1 method without executing any other code to see if it functions as expected. I also recommend to look into the ConditionalSleep classes. Standard ConditionalSleep class new ConditionalSleep(maxSleepTime, checkInterval) { @Override public boolean condition() throws InterruptedException { return condition; } }.sleep(); Non-Standard ConditionalSleep class - I personally recommend using this one, as it is more straightforward. ConditionalSleep2.sleep(maxSleepTime, () -> condition) Edited February 4, 2022 by BravoTaco Quote Link to comment Share on other sites More sharing options...
mrdukesilver Posted February 17, 2022 Author Share Posted February 17, 2022 On 2/5/2022 at 1:47 AM, BravoTaco said: @mrdukesilver Without having knowledge of the code inside of the other methods, this will be rather hard to debug. Try executing only the worldHop1 method without executing any other code to see if it functions as expected. I also recommend to look into the ConditionalSleep classes. Standard ConditionalSleep class new ConditionalSleep(maxSleepTime, checkInterval) { @Override public boolean condition() throws InterruptedException { return condition; } }.sleep(); Non-Standard ConditionalSleep class - I personally recommend using this one, as it is more straightforward. ConditionalSleep2.sleep(maxSleepTime, () -> condition) Hey! , tysm for responding, can u tell me how can I use this in my code, could you kindly provide me an example pls? Quote Link to comment Share on other sites More sharing options...
BravoTaco Posted February 22, 2022 Share Posted February 22, 2022 (edited) On 2/17/2022 at 2:04 PM, mrdukesilver said: Hey! , tysm for responding, can u tell me how can I use this in my code, could you kindly provide me an example pls? Sure! No problem! // Basic code to chop a regular tree, with a conditional sleep, when the player is not animating. if (!myPlayer().isAnimating()) { RS2Object tree = getObjects().closest("Tree"); if (tree != null && tree.interact("Chop down")) { // The conditional sleep returns true or false. // True being returned if the condition is met. IE. The player is animating. // False being returned if the condition is not met, and the max sleep time is met. // The sleep time is in milliseconds so 15000 == 15 seconds. if (ConditionalSleep2.sleep(15000, () -> myPlayer().isAnimating())) { log("Player is chopping the tree."); } } } Edited February 22, 2022 by BravoTaco Quote Link to comment Share on other sites More sharing options...