Jump to content

Trying to store my inventory on start up.


shaba123

Recommended Posts

Im trying to store my inventory on start up and everytime i go to the bank i want to check if my inventory is the same as onstart, if not, withdraw items from bank to match.

This is what i have so far :

   public void onStart() {
    	
    	Item[]initial = getInventory().getItems();
    	log(initial);

    }

This must be an incorrect way to grab items as this is what comes up in the log :

[INFO][Bot #1][05/25 10:06:18 AM]: [Lorg.osbot.rs07.api.model.Item;@122d063

Do i need to display the results differently?

 

 

And this is what im doing to check for any changes in the inventory: 

		if (getBank().isOpen()) { 

    		for (int i = 0; i < inventory.getItems().length; i++) {
        		Item current = inventory.getItems()[i]; 
        		Item in = initial[i]; 
        		
        		if (in.getAmount() != current.getAmount()) { 
        			log("Invent is different");
                    // code to withdraw initial from bank                                     
        			return;
        		}
    	}
    	}

I believe im just grabbing the initial inventory items wrong onstart  which makes the code to check for inventory changes obsolete. 

Please correct my errors and tell me where im going wrong, thank you.

Link to comment
Share on other sites

...

You're printing the array, so what comes up is expected.

If you want to print the array's contents you will need to loop over it and print each Item, or use Arrays.toString():
 

log(Arrays.toString(initial));


Questions like this can be easily answered using Google, all you need to search for is "How to print an array in Java".

Edited by Explv
  • Like 2
Link to comment
Share on other sites

Thank you for your help 

53 minutes ago, Explv said:

...

You're printing the array, so what comes up is expected.

If you want to print the array's contents you will need to loop over it and print each Item, or use Arrays.toString():
 


log(Arrays.toString(initial));


Questions like this can be easily answered using Google, all you need to search for is "How to print an array in Java".

 

Link to comment
Share on other sites

1 hour ago, Alek said:

You're trying to print an array...
 

How do i use my arrayList, im trying to check that my inventory has not chnaged since i started the script,would it be like so :

 

edit: i know what i have done is not correct i just dont know how to use the array of items

		if (getBank().isOpen()) { 

    		for (int i = 0; i < inventory.getItems().length; i++) {
        		Item current = inventory.getItems()[i]; 
        		Item in = Arrays.toString(initial)[i]; 
        		
        		if (in.getAmount() != current.getAmount()) { 
        			log("Invent is different");
                    // code to withdraw initial from bank                                     
        			return;
        		}
    	}
    	}

 

1 hour ago, Explv said:

...

You're printing the array, so what comes up is expected.

If you want to print the array's contents you will need to loop over it and print each Item, or use Arrays.toString():
 


log(Arrays.toString(initial));


Questions like this can be easily answered using Google, all you need to search for is "How to print an array in Java".

 

Edited by shaba123
Link to comment
Share on other sites

Do i have to save the array list to a string like this :

String[] items = new String[] (initial);

then it would be :

	if (getBank().isOpen()) {

    		for (int i = 0; i < inventory.getItems().length; i++) {
        		Item current = inventory.getItems()[i]; 
        		Item in = item[i]; 
        		
        		if (in.getAmount() != current.getAmount()) { 
        			log("Invent is not the same");
        			return;
        		}

Im watching some video tutorials on java now i have lots of learning to do.

 

EDIT: could a mod merge my last 3 posts please im making a mess of the forums!

 

EDIT: i managed to solve it , thanks for everyones help.

Edited by shaba123
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...