Smuds Posted January 20, 2017 Posted January 20, 2017 (edited) editted for terrible formatting (and continued formatting) So for my first few scripts I've just been using normal sleep where it waits a random amount of time before going on to the next action. But I saw that it was recommended to minimize that form and prioritize conditional sleep in scripts. From my understanding, conditional sleep continues only in the case of (A) the condition has been met or (B) the timeout has expired. However, what happens if the interior condition is immediately proved true, but a new action can't occur because of a necessary wait time? Alching, for example, would just result in a ridiculous amount of spamming when used like - if(script.inventory.interact("CAST", "Maple Bow")){ new ConditionalSleep(1200) { public boolean condition() throws InterruptedException return !script.myPlayer().isAnimating(); } }.sleep(); Edited January 20, 2017 by Smuds
wwwat Posted January 20, 2017 Posted January 20, 2017 I'm sure if you put a small sleep right before the conditional it would work
Hayase Posted January 20, 2017 Posted January 20, 2017 Change the sleep to return when the player is animating. This way after you interact, it will sleep until you are animating. if(script.inventory.interact("CAST", "Maple Bow") && !script.myPlayer().isAnimating()){ new ConditionalSleep(1200) { public boolean condition() throws InterruptedException return script.myPlayer().isAnimating(); } }.sleep();
Smuds Posted January 20, 2017 Author Posted January 20, 2017 I'm sure if you put a small sleep right before the conditional it would work A mix of the two does seem desirable, but at that point, it almost seems like you might as well just use a plain sleep because that's what is actually doing the waiting. Change the sleep to return when the player is animating. This way after you interact, it will sleep until you are animating. if(script.inventory.interact("CAST", "Maple Bow") && !script.myPlayer().isAnimating()){ new ConditionalSleep(1200) { public boolean condition() throws InterruptedException return script.myPlayer().isAnimating(); } }.sleep(); The way I understand it, the problem is not that the player is animating, it's that there's something like a cool down for the spell. If that is the case, then this wouldn't change the problem.
Hayase Posted January 20, 2017 Posted January 20, 2017 A mix of the two does seem desirable, but at that point, it almost seems like you might as well just use a plain sleep because that's what is actually doing the waiting. The way I understand it, the problem is not that the player is animating, it's that there's something like a cool down for the spell. If that is the case, then this wouldn't change the problem. You can set your onloop() to handle things like this and other issues. You know for sure that the onloop() is going to be looping until script stop. You can define the cooldown then the conditional sleep after like another poster said. Alching is like a 2s delay? do your sleep(2000,2500) and put your conditionalsleep after.
FrostBug Posted January 21, 2017 Posted January 21, 2017 could change the sleep condition to 'item stack amount decreased && not animating anymore' 2
Saiyan Posted January 21, 2017 Posted January 21, 2017 could change the sleep condition to 'item stack amount decreased && not animating anymore' long itemCount = getInventory().getAmount("Item"); if(getMagic().castSpell(Spells.NormalSpells.SPELL_NAME)) { new ConditionalSleep(3000) { public boolean condition() throws InterruptedException return !script.myPlayer().isAnimating() && getInventory().getAmount("Item") < itemCount; // if our new inventory count of the alch item is less than the previouscount } }.sleep(); } did this without an ide so there may be typos etc
Smuds Posted January 21, 2017 Author Posted January 21, 2017 Yeah I think that would definitely work, I'll put it in and report back how it works.
liverare Posted January 21, 2017 Posted January 21, 2017 could change the sleep condition to 'item stack amount decreased && not animating anymore' That, or alternatively: var ALCH_WAIT_IN_MS = 1000 var lastAlchTime IF currentSysTime LESS THAN lastAlchTime THEN wait ELSE IF performAlchClick THEN SET lastAlchTime TO currentSysTime + ALCH_WAIT_IN_MS