Solved Help with for loops - integers

Discussion in 'Plugin Development' started by Failplease, Dec 27, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Failplease

    How would I make it so that a set of ints are looped through with an int's value increasing each time until the int value is not equal to the value of any int in the set?

    Thanks for any help.
     
  2. Offline

    Failplease

    Bumpedy bump.
     
  3. Offline

    Jaker232

    Failplease
    Are you talking about "for" loops?
     
  4. Offline

    Timbals

    When the ints are saved in a (Array)List then do that to loop through all the ints:
    Code:java
    1. for(int i : intlist){
    2. //Do whatever you wanna do
    3. //everything you do with i will be done for every int in the list
    4. }
     
  5. Offline

    Failplease

    Timbals
    Ok, I see, but how would I make it only issue a code when the last index of the ArrayList is reached?
     
  6. Offline

    GaaTavares

    Hmm...
    something like that?
    Code:java
    1. for (int i =0; i < intlist.size(); i++){
    2. if (i == intList.size()){
    3. //stuff
    4. }}
     
  7. Offline

    jthort

    You could use a do-while loop
     
  8. Offline

    Failplease

    Ok so this is solved, but how would I get all parent strings in a config and use that as a list. Example config:
    Code:
    0:
      pie: Pie is good!
      chicken: Tastes like chicken!
      turkey: Who likes turkey?
    1:
      pie: Pie is good!
      chicken: Tastes like chicken!
      turkey: Who likes turkey?
    2:
      pie: Pie is good!
      chicken: Tastes like chicken!
      turkey: Who likes turkey?
    In that config what I want would be the list that contains 0, 1, and 2.

    Anyone...?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  9. Offline

    Tster

    This might help
    "The getKeys(boolean) method returns the set of keys for the current FileConfigurationSection. The boolean value determines if the returned set is recursive, if true it will return the keys of the given section and their children keys"
    so getConfig().getKeys(false)
     
  10. Offline

    Failplease

    Ok Tster and others,

    I have this code, but it does nothing:
    Code:
    for(String s : keys) {
        int i = Integer.parseInt(s);
        if(i == keys.size()) {
            String id = String.valueOf(i + 1);
            plugin.getConfig().set(id + ".x", bl.getBlockX());
            plugin.getConfig().set(id + ".y", bl.getBlockY());
            plugin.getConfig().set(id + ".z", bl.getBlockZ());
        }
    }
    "keys" is defined as "plugin.getConfig().getKeys(false);"

    What am I doing wrong that causes nothing to happen?
     
  11. Offline

    Tster

    So you're asking 'if one of the keys is equal to the total number of keys'?. Is that what you want?
     
  12. Offline

    Failplease

    Tster
    Yes, because that basically gets the highest int in the config.
     
Thread Status:
Not open for further replies.

Share This Page