This site requires JavaScript, please enable it in your browser!
Greenfoot back
Barador
Barador wrote ...

2012/11/29

Variable does not update

Barador Barador

2012/11/29

#
Hi In my Game I have a class which has two subclasses. In my class I have defined a boolean. This boolean is to be set in the first subclass und checked if true in the other one. My problem is that in my first subclass where the boolean is set to true it's updated correctly, but in the other one it's always at false (I inspected the objects during run). Do you have an idea?
-nic- -nic-

2012/11/29

#
post te code where the boolean gets updated by the first class
Barador Barador

2012/11/29

#
Actor box;
        box = getOneObjectAtOffset (0, 0, Box.class);
        if (box != null)
        {
            setLocation(getX(), getY() - 300);
            jumped = true;
        }
-nic- -nic-

2012/11/29

#
you have set jumped to "1" which is a int and you are talking about a boolean which takes either "true" or "false"
Barador Barador

2012/11/29

#
Yes i updated it now, because I also tried it with an int.
-nic- -nic-

2012/11/29

#
would you need to do (im not sure on class hiericy)
parenclass.jumped = true; 
?
Barador Barador

2012/11/29

#
No he sais cannot find symbol variable parenclass
Barador Barador

2012/11/29

#
Ah you mean this! if I insert
Objects.jumped = true;
jumped is underlined with "non-static variable cannot be referenced from a static content"
-nic- -nic-

2012/11/29

#
public static boolean jumped = false; should sort that
Barador Barador

2012/11/29

#
Thanks a lot it works now!
-nic- -nic-

2012/11/29

#
its okay :)
You need to login to post a reply.