Jump to content

inventory.contains slow?


Novak

Recommended Posts

Mine:

Called
Sleep
Sleep
Sleep
Sleep
Sleep
Sleep
Sleep
Sleep
Sleep
Sleep
Sleep
Sleep
Sleep
Sleep
Sleep
Sleep
Sleep
Sleep
Sleep
Sleep
Sleep
 

public boolean contains(int i) {
System.out.println("Called");
return true;
}
 
public void check() {
if (contains(0)) {
for (int i = 0; i < 100; i++) {
System.out.println("Sleep");
}
}
}

Yours

Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
Sleep
Called
 

public boolean contains(int i) {
System.out.println("Called");
return true;
}
 
public void check() {
for (int i = 0; i < 100 && contains(0); i++) {
System.out.println("Sleep");
}
}

Hypothetical, but yeah.

sure, but you are arguing over a minimal cpu hit which is not what i am asking.  I am asking why .contains is getting updated so late after the inventory has changed. calling it over should not affect what the output of the call is

 

 

and also:

 

yours says if inventory contains item:

 

sleep for 5 seconds, because there is no condition for the for statement except that i is less than 100.

Edited by Novak
Link to comment
Share on other sites

so im a bit confused, what exactly are you trying to accomplish here? Your saying innvnetory.contains is slow? its a boolean what you mean. Are your rying to say the deposit method is slow?

 

 

no.  

 

im saying the inventory.contains does not update its value(true/false) for a long time after it is actually true/false.

 

example:

 

i deposit item A into the bank from my inventory.

when the item disappears, inventory.contains should be false.

instead, it is still true for another couple seconds, slowing down the script

Edited by Novak
Link to comment
Share on other sites

in the OP i state i am using a for loop that sleeps until inventory.contains is no longer true, so it wont exit that loop until it is false OR it times out at 5 seconds

i meant shouldnt the value change after the onLoop finishes looping though? thats what i think. I never really had a problem with inventory.contains

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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