Hello, it is me again,
I am having trouble with changing a boolean of an actor from the world in which the actor was added.
For example, I set the world 'Level1.class'. This world adds the objects in the world.
It also has the boolean 'started':
Now I want to have a method to change the boolean 'started' of the actors. This 'started' is not the same as the one in the world class.
This is in the constructor of the class 'KI', which is the superclass of Elefant. Actually it is the superclass of the superclass, but I do not think that this matters.
I want to change the boolean 'started' of the actors to true, when the boolean 'started' in the world class was set to true.
My first try was like this:
But if I try to compile, it says "cannot find symbol - variable ele1". I thought that ele1 was defined earlier when I created the object ele1 from the class Elefant and would now refer to this object. But this is apparently not the case.
This was my second try:
But now, I get the error 'cannot find symbol - variable started'.
What am I doing wrong? The variable 'started' is public in the KI.class as I said. What is the reason why the compiler is not able to find it? How can I change the boolean of the actors from the world class?
By the way, I did the second way exacty the same with only taking the subclass Eelefant instead of the superclass KI and using the number of them instead of 'gegner'. Of course I put the variable from the KI constructor to Elefant, too. I wanted to see, if that caused the problem, but I did not.
1 2 3 4 5 6 | Elefant ele1 = new Elefant( getEle1a(), getEle1b() ); addObject(ele1, getEle1x(), getEle1y() ); Elefant ele2 = new Elefant( getEle2a(), getEle2b() ); addObject(ele2, getEle2x(), getEle2y() ); Elefant ele3 = new Elefant( getEle3a(), getEle3b() ); addObject(ele3, getEle3x(), getEle3y() ); |
1 | public static boolean started = false ; |
1 | public boolean started = false ; |
1 2 3 4 5 6 7 8 9 | public void act() { if (started) { ele1.started = true ; ele2.started = true ; ele3.started = true ; } } |
1 2 3 4 5 6 7 8 9 10 | public void act() { if (started) { for ( int i = 0 ; i<gegner- 1 ; i++) //'gegner' is an int. It is the number of enemies which are added in this level. { getObjects(KI. class ).get(i).started = true ; } } } |