Jump to content

Conditional Sleep Confusion


Smuds

Recommended Posts

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
Link to comment
Share on other sites

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();
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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