Thread: Help with RuneSource Arrays

Results 1 to 7 of 7
  1. #1 Help with RuneSource Arrays 
    Registered Member reapergrim's Avatar
    Join Date
    Oct 2009
    Posts
    52
    Thanks given
    4
    Thanks received
    2
    Rep Power
    26
    Hello everyone, If this is the wrong section please let me know.

    I am having difficulty making a Total wealth of my server, for example, if I have a commmand thats :erverwealth, I want it to send a message saying the total wealth of the server. I do have a getWealth method, but when I put the array in my command it sends the message in game but for every playerSave that I have, which looks like this:



    This is the code that's producing it:

    Code:
    if (keyword.equals("totalw")) { //Kinda works no total
                           for (Hplayer player : PlayerSave.listOfPlayersAll) {		
    		            getActionSender().sendMessage("There is currently @[email protected]" + player.getWealthAll() + " @[email protected] of gold in the server");
    Instead of it printing multiple lines of each individual characters wealth, how do I instead multiply it to where it will only print 1 line with all characters wealth combined. I've googled and researched a lot of different methods using sum of elements, etc. Just can't quite figure it out.

    Thanks.

    PS: still learning arrays, so any help would be appreciated.
    Reply With Quote  
     

  2. #2  
    Registered Member
    Join Date
    Jul 2022
    Age
    29
    Posts
    8
    Thanks given
    0
    Thanks received
    3
    Rep Power
    0
    Your sending the message inside of a for loop you need declare an variable outside of the loop add each players value to the variable and the print that variable outside of the loop
    Reply With Quote  
     

  3. #3  
    Registered Member reapergrim's Avatar
    Join Date
    Oct 2009
    Posts
    52
    Thanks given
    4
    Thanks received
    2
    Rep Power
    26
    Quote Originally Posted by Arumat View Post
    Your sending the message inside of a for loop you need declare an variable outside of the loop add each players value to the variable and the print that variable outside of the loop
    Do I need to add an additional for loop for players and then multiply them? My understanding is if I get what your saying is correct, I would have to put each individual player into an array list and do it that way? Sorry If I'm quite not understanding yet.
    Reply With Quote  
     

  4. #4  
    Registered Member
    Join Date
    Jul 2022
    Age
    29
    Posts
    8
    Thanks given
    0
    Thanks received
    3
    Rep Power
    0
    To clarify your goal is to return a number that is the sum of every players wealth combined right?
    Reply With Quote  
     

  5. #5  
    Registered Member reapergrim's Avatar
    Join Date
    Oct 2009
    Posts
    52
    Thanks given
    4
    Thanks received
    2
    Rep Power
    26
    Quote Originally Posted by Arumat View Post
    To clarify your goal is to return a number that is the sum of every players wealth combined right?
    yes that is correct, I have a mess of spaghetti that I've tried and seem to not be successful, with a return of 0 instead, Im understanding the size of a players bank is probably 0 because it doesnt know where its pulling bank sizes from and multiplying players, which would return 0.

    Here's what I have tried:

    Code:
    //int sum = 0;
    				/*int size = bank.size();
    				int size2 = PlayerSave.listOfPlayersAll.size();
    				int myArray[] = new int [size];
    				int myArray2[] = new int [size2];*/
    				/*int myArray[] = new int[bank.size()];
    				int myArray2[] = new int[PlayerSave.listOfPlayersAll.size()];
    
    				int lengthOfArray = myArray.length;
    				int lengthofArray2 = myArray2.length;
    
    				int[] total = new int[lengthOfArray * lengthofArray2];*/
    Even so it still loops all players, so I get 400+ sendMessage in the chat box of 0
    Reply With Quote  
     

  6. #6  
    Registered Member
    Join Date
    Jul 2022
    Age
    29
    Posts
    8
    Thanks given
    0
    Thanks received
    3
    Rep Power
    0
    Code:
    private void foobar() {
    	long value = 0; //long value as combined wealth would exceed the max value of an integer
    
    	//loop anything contained within the loop with execute per object in the loop
    	for (Hplayer player : PlayerSave.listOfPlayersAll) {
    		value = value + player.getWealthAll();
    	}
    	//Sending the message after the loop will only print the message once instead of for every player
    	getActionSender().sendMessage("There is currently @[email protected]" + value + " @[email protected] of gold in the server");
    }
    Hopefully this will help as long as your player.getWealthAll(); is returning the correct value you want this should work

    Alternatively you could use lambda functionality but stick to some basic stuff for now
    Reply With Quote  
     

  7. Thankful user:


  8. #7  
    Registered Member reapergrim's Avatar
    Join Date
    Oct 2009
    Posts
    52
    Thanks given
    4
    Thanks received
    2
    Rep Power
    26
    EDIT: Got it all figured out thank you!


    Quote Originally Posted by Arumat View Post
    Code:
    private void foobar() {
    	long value = 0; //long value as combined wealth would exceed the max value of an integer
    
    	//loop anything contained within the loop with execute per object in the loop
    	for (Hplayer player : PlayerSave.listOfPlayersAll) {
    		value = value + player.getWealthAll();
    	}
    	//Sending the message after the loop will only print the message once instead of for every player
    	getActionSender().sendMessage("There is currently @[email protected]" + value + " @[email protected] of gold in the server");
    }
    Hopefully this will help as long as your player.getWealthAll(); is returning the correct value you want this should work

    Alternatively you could use lambda functionality but stick to some basic stuff for now
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Need help with Model arrays
    By ZionHacker in forum Help
    Replies: 0
    Last Post: 11-22-2018, 05:09 PM
  2. Need help with increasing arrays? :)
    By _Mario in forum Help
    Replies: 2
    Last Post: 06-23-2016, 03:35 PM
  3. Replies: 5
    Last Post: 09-15-2014, 08:13 PM
  4. Help with RuneSource.
    By strongbow in forum Help
    Replies: 0
    Last Post: 01-01-2011, 02:53 PM
  5. [508] Need help with an array list, will rep+
    By EndlessZombies in forum Help
    Replies: 5
    Last Post: 04-22-2009, 03:08 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •