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

2025/1/31

Access to variables of other classes

Jder2te Jder2te

2025/1/31

#
I need to access a variable from another class. this works for one of them, but for some reason the second variable is not changing.
Spieler1 Spieler1;
    
    
    public void act()
    {
    if(Greenfoot.isKeyDown("d"))
    {
         setLocation(getX() + 3, getY());
         
         if(Spieler1.Kollision1 == true)
         {setLocation(getX() - 3, getY());}
    }
That is the second variable with does not work,
if(Spieler1.Leben1 == 3)
    {
        setImage("Lebensanzeige1_3.png");
    }
in this example the method does work. did I make a syntax mistake or something ?
danpost danpost

2025/2/1

#
Jder2te wrote...
I need to access a variable from another class. this works for one of them, but for some reason the second variable is not changing. << Code Omitted >> That is the second variable with does not work, << Code Omitted >> in this example the method does work. did I make a syntax mistake or something ?
Very confusing as far as which one worked and which one didn't. I hope you are not expecting the collision variable to update when all you did was move this actor. You performed no collision checking between the setting of the actors location and the testing of the collision variable.
You need to login to post a reply.