Why my boolean variable doesn't get updated on other classes?

Kevin Bryan

I made a boolean called endGame, and when I click a button it will be set to false, and then on another class I made an object for the class where my boolean is. And when something happen the endGame will be set to true:

if(condition==true){ //the endGame variable will be equal to true only on this class
 classObj.endGame=true;
}

//on the other class where the endGame is Located it is still false.



   //button class
public boolean endGame;
    public void create(){
    endGame=false;

     playButton.addListener(new InputListener(){
               @Override
               public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                   endGame=false;
                   System.out.println(endGame);
                   return super.touchDown(event, x, y, pointer, button);
               }
           });
    }

    //second class
    if(sprite.getY()>=700){
       buttonObj.endGame=true;
       enemyIterator.remove();
       enemies.remove(sprite);
    }
Eran

and then on another class I made an object for the class where my boolean is

I assume the endGame variable is not static. Otherwise you wouldn't need to create an object of the class where the boolean is in order to access it.

This means that if you set endGame to true in one object of the relevant class, it wouldn't update the value of endGame in different objects of that class.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why doesn't environment variable get updated in cmd without restart?

From Dev

Variable doesn't get updated in if else statement

From Dev

Why doesn't my app's theme get updated in my main activity anymore?

From Dev

Boolean variable does not get updated

From Dev

$scope value doesn't get updated in other controller

From Dev

Why isn't my for loop using the updated global variable?

From Dev

Why doesn't my subclass' variable exist?

From Dev

Why Make doesn't recognize my variable?

From Dev

why conditional or doesn't evaluates to boolean value when assigned to a variable

From Dev

Variable doesn't get updated in the function of Batch file

From Dev

Why doesn't the Value get replaced in the variable?

From Dev

Why doesn't my variable value get passed to the finally block in python

From Dev

Why doesn't my variable save to my array in JavaScript?

From Dev

TextView doesn't get updated

From Dev

Why doesn't lldb forward my environment variable anymore?

From Dev

Why doesn't changing the value of my global variable take effect?

From Dev

Why my method doesn't call the another one (undefined variable)

From Dev

Why isn't my method adding up the values in my other classes? (sscce included)

From Dev

Why is my boolean variable messed up?

From Dev

Why my helper doesn't re-run when the collection I call inside it is updated?

From Dev

Why does my map function doesn't work after updated Redux state with react

From Dev

My getters won't give an updated variable

From Dev

SetBool doesn't save my boolean statements

From Dev

Updated variable doesn't maintain it's updated value

From Dev

Updated variable doesn't maintain it's updated value

From Dev

Why doesn't ReadTheDocs show "Last updated on"

From Dev

Why doesn't my browser make a difference between classes and ids in my thread?

From Dev

Why isn't my map being updated?

From Dev

Why isn't my record getting updated?

Related Related

  1. 1

    Why doesn't environment variable get updated in cmd without restart?

  2. 2

    Variable doesn't get updated in if else statement

  3. 3

    Why doesn't my app's theme get updated in my main activity anymore?

  4. 4

    Boolean variable does not get updated

  5. 5

    $scope value doesn't get updated in other controller

  6. 6

    Why isn't my for loop using the updated global variable?

  7. 7

    Why doesn't my subclass' variable exist?

  8. 8

    Why Make doesn't recognize my variable?

  9. 9

    why conditional or doesn't evaluates to boolean value when assigned to a variable

  10. 10

    Variable doesn't get updated in the function of Batch file

  11. 11

    Why doesn't the Value get replaced in the variable?

  12. 12

    Why doesn't my variable value get passed to the finally block in python

  13. 13

    Why doesn't my variable save to my array in JavaScript?

  14. 14

    TextView doesn't get updated

  15. 15

    Why doesn't lldb forward my environment variable anymore?

  16. 16

    Why doesn't changing the value of my global variable take effect?

  17. 17

    Why my method doesn't call the another one (undefined variable)

  18. 18

    Why isn't my method adding up the values in my other classes? (sscce included)

  19. 19

    Why is my boolean variable messed up?

  20. 20

    Why my helper doesn't re-run when the collection I call inside it is updated?

  21. 21

    Why does my map function doesn't work after updated Redux state with react

  22. 22

    My getters won't give an updated variable

  23. 23

    SetBool doesn't save my boolean statements

  24. 24

    Updated variable doesn't maintain it's updated value

  25. 25

    Updated variable doesn't maintain it's updated value

  26. 26

    Why doesn't ReadTheDocs show "Last updated on"

  27. 27

    Why doesn't my browser make a difference between classes and ids in my thread?

  28. 28

    Why isn't my map being updated?

  29. 29

    Why isn't my record getting updated?

HotTag

Archive