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

2023/4/22

How do i permanently remove an object.

alex90 alex90

2023/4/22

#
so in my program, i have to save a cat by picking a cat and returning it to their owner. if i touch the cat it disappears but if i leave the world and go in it again the cat reappears. is there any way to stop this?
danpost danpost

2023/4/22

#
alex90 wrote...
so in my program, i have to save a cat by picking a cat and returning it to their owner. if i touch the cat it disappears but if i leave the world and go in it again the cat reappears. is there any way to stop this?
That is what you probably are NOT doing -- "go in it again". Go back to the same world. Do not create a new one by using the 'new' keyword.
alex90 alex90

2023/4/24

#
if i try to delete it then it says thatvariable isnt declared
alex90 alex90

2023/4/24

#
public void new_world()
    {
        //up
        if(getY() == 0)
        {
            Greenfoot.setWorld(new world2());
            if (getWorld() instanceof world2)
            {
                Greenfoot.setWorld(new world3()); 
            }
             if (getWorld() instanceof world6)
            {
                Greenfoot.setWorld(new world5()); 
            }
             if (getWorld() instanceof world5)
            {
                Greenfoot.setWorld(new world4()); 
            }
            if (getWorld() instanceof world7)
            {
                Greenfoot.setWorld(new world8()); 
            }
            if (getWorld() instanceof world8)
            {
                Greenfoot.setWorld(new world9()); 
            }
        }
        //down
        if (getY() == getWorld().getHeight() - 1)
        {
            Greenfoot.setWorld(new world2());
            if (getWorld() instanceof world2)
            {
                Greenfoot.setWorld(new world1());  
            }
             if (getWorld() instanceof world4)
            {
                Greenfoot.setWorld(new world5()); 
            }
             if (getWorld() instanceof world5)
            {
                Greenfoot.setWorld(new world6()); 
            }
            if (getWorld() instanceof world9)
            {
                Greenfoot.setWorld(new world8()); 
            }
            if (getWorld() instanceof world8)
            {
                Greenfoot.setWorld(new world7()); 
            }
        }
        //left
        if(getX() == 0)
        {
            Greenfoot.setWorld(new world6());
            if (getWorld() instanceof world2)
            {
                Greenfoot.setWorld(new world5()); 
            }
             if (getWorld() instanceof world3)
            {
                Greenfoot.setWorld(new world4()); 
            }
            if (getWorld() instanceof world6)
            {
                Greenfoot.setWorld(new world7()); 
            }
            if (getWorld() instanceof world5)
            {
                Greenfoot.setWorld(new world8()); 
            }
            if (getWorld() instanceof world4)
            {
                Greenfoot.setWorld(new world9()); 
            }
        }
        //right
        if(getX() == getWorld().getWidth() - 1)
        {
            Greenfoot.setWorld(new world1());
            if (getWorld() instanceof world5)
            {
                Greenfoot.setWorld(new world2()); 
            }
             if (getWorld() instanceof world4)
            {
                Greenfoot.setWorld(new world3()); 
            }
            if (getWorld() instanceof world7)
            {
                Greenfoot.setWorld(new world6()); 
            }
            if (getWorld() instanceof world8)
            {
                Greenfoot.setWorld(new world5()); 
            }
            if (getWorld() instanceof world9)
            {
                Greenfoot.setWorld(new world4()); 
            }
        }
    }
alex90 alex90

2023/4/24

#
this is the code
danpost danpost

2023/4/24

#
alex90 wrote...
if i try to delete it then it says thatvariable isnt declared << Code Omitted >> this is the code
You have 9 different worlds. That is not bad, in and of itself; but, I am sure it would be taxing on memory if you all of them existing at the same time. So, my first suggestion may not be the best approach. Since I do not know anything about your worlds, no suggestion can be formulated at this time. Please provide world class codes for which cat is initially located. Now, if there was a way to "save" your worlds using minimal data (without saving the worlds themselves), that might be a way to go (so you can re-create the worlds, when needed, as they were).
You need to login to post a reply.