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

2012/10/27

Making actor appear/dissapear?

SimpleJack SimpleJack

2012/10/27

#
Hi, I want to make my warning actors appears based on booleans from my player class. Player: (called player)
if (dirt == 0)
        {
            dirty = false;
        }
        else if (dirt == 1)
        {
            dirty = true;
        }
world (called house)
player myPlayer = new player();
boolean existsDirty = false;

if (myPlayer.dirty)
        {
            if (!existsDirty)
            {
            
             addObject(new warningDirty() , 300, 200);
             existsDirty = true;
            }
        }

        if (!myPlayer.dirty & existsDirty)
         {
           existsDirty = false;
           warningDirty myWarning = new warningDirty();     
           removeObject(myWarning);
           System.out.println("Passed Through");
         }
       
I have it wired that when i press t it changes dirt = 1 and dirty = true and when i press y dirt = 0 and dirty = false but when i press y all the variables change and the "Passed through" is printed but the object is not removed... help?
danpost danpost

2012/10/27

#
Line 17 in the house class code creates a new 'warningDirty()' object and line 18 attempts to removes the one just created from the world (which in effect, does nothing, since it has not been placed in the world). The 'warningDirty' object that you already have in the world is not even mentioned in the 'if' block in question. The key words in the last sentence are "'warningDirty' object in world".
You need to login to post a reply.