Global Arrays

Discussion in 'Plugin Development' started by HSAR, Aug 17, 2011.

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

    HSAR

    Hey guys, I feel like I'm missing something that should be obvious here.

    I have a code section that looks like this:

    Code:
    DropManifest = config.getString("DropManifest", "pork,water,pick,chest,sword,torch");//default drop list
    
            String[] DropManiArr = DropManifest.split(",",64); //converts CSV to array
    
            String[][] FullManiArr = new String[DropManiArr.length][3];
    This works fine. However, since this code is called onEnable both arrays DropManiArr and FullManiArr are local to onEnable (it seems). I've tried declaring them before onEnable, but the problem is the size of the arrays aren't fixed.

    Is there any way to be able to set them to be global from within onEnable, since it's not possible to change array sizes after creation?

    Thanks in advance,
    HSAR
     
  2. Offline

    bergerkiller

    You can declare the 2/3 members as static, but you probably need to initialize them elsewhere then. (in onEnable)
    Code:
            public static String[] DropManiArr;
            public static String[][] FullManiArr;
    Somewhere else:
    Code:
    DropManiArr = DropManifest.split(",",64); //converts CSV to array
    FullManiArr = new String[DropManiArr.length][3];
     
  3. Offline

    RedFoxRedI

    As long as you write the fields outside of any method, but inside the class, they are global.
    Code:
    public class Example{
        public int[] multiplesOfNine = new int[]{9,18,27};
    
        public void toSomething(){
          ...
        }
    }
     
Thread Status:
Not open for further replies.

Share This Page