Jump to content

Conditional Sleep Confusion


Recommended Posts

Posted (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 by Smuds
Posted

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();
Posted

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.

Posted

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.

Posted

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...