Jump to content

how to define If then no items left


peilis

Recommended Posts

Hello,

 

How should i define the "if" statement for finishing my script ? It should finish then there is no specific item in the bank. So then that condition is met, it will go to a state that will stop the script / logout.

private State getState() {
Item something = bank.getItem("specific item");
if (something == null) 
return State.FINISHED;

if (something.getAmount() == 0)
return State.FINISHED;

case FINISHED:
stop();
logoutTab.logOut();
break;

So i tried 2 different ways, yet what happens is : i start the script and the condition for it is met and it just do the stuff in FINISHED state.

 

This is my first script, so im not used to the osbot api and not sure how some method works.

Link to comment
Share on other sites

Hopefully thats your problem 

private State getState() {
Item something = bank.getItem("specific item");
if (something == null) 
return State.FINISHED;
}


 

private State onLoop() {
case FINISHED:
if (something.getAmount() == 0){
stop();
logoutTab.logOut();
}
break;

 

Edited by Ispecyou
Link to comment
Share on other sites

I tried to do as Ispecyou showed, yet it looks like my client freezes then i try to use .getAmount() method. I can see people walking arround, yet i cannot stop the script, nor exit the client, the only way to exit is to kill process.

private State getState() {
Item something = bank.getItem("specific item");
boolean something = bank.contains("specific item");
}

These 2 lines in getState() will return null or false not sure why it is like that.

 

But it works if i start the script while bank is open.

private State getState() {
boolean something = bank.contains("specific item");
if (!something) 
return State.FINISHED;
}

Yet, im quite confused why it does not get the correct value while bank is closed.

Item something = bank.getItem("specific item");

Maybe there is another better way of doing it ? Not necessary according to what i have ? - no specific item left in bank -> go to state.

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...