Jump to content

Trying to store my inventory on start up.


Recommended Posts

Posted

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.

Posted (edited)

...

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
Posted

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

 

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

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

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