3 Replies Latest reply: Jan 2, 2008 1:14 PM by 807601 RSS

    Trouble setting global boolean variables

    807601
      Hello,

      I'm having trouble setting global boolean variables in my code.
      Somehow I can read their values but I can not set them to 'true' or 'false' (unless I hard-code it, of course).
      Here's my code:
      class test {
           // goals, true = goal is active
           static boolean goal0 = false;
           static boolean goal1 = false;
           static boolean goal2 = false;
           static boolean goal3 = false;
           static boolean goal4 = false;
           static boolean goal5 = false;
           static boolean goal6 = false;
           static boolean goal7 = false;
      
           // array of goals
           static boolean[] goals = {
                goal0, goal1, goal2, goal3, goal4, goal5, goal6, goal7
           };
      
      
           static void setGoals() {
                goal0 = true;
                goal2 = true;
                goal4 = true;
                goal6 = true;
           }
      
      
           public static void main(String [] args) {
                setGoals();
      
                System.out.println("goals:");
      
                // goals status
                for(int d=0; d<goals.length; d++) {
                     System.out.println(d + ": " + goals[d]);
                }
      
                System.out.println();
           }
      }
      When I run this program all variables are 'false', even if I run the function 'setGoals()' to set a few of them to 'true'.
      Can someone explain why this happens and how I can fix it?

      Thanks a lot in advance,

      Abel.