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

2015/3/9

Deleting a actor

KiwiMC1482 KiwiMC1482

2015/3/9

#
Okay so far i have
if( Greenfoot.getKey().equals("backspace")) 
   {
       removeObject( new Mnim());
   }
which complies fine but doesn't actually delete the last minim created and I don't really know what i'm doing wrong
danpost danpost

2015/3/9

#
Your line 3 is creating a new Mnim object and then attempt to remove it from the world. Well, it was just created and was never placed into the world. Besides, it is not the object instance you want to remove from the world at any rate. If you do not have a reference to the Mnim instance you wish to remove from the world, then you will have to get it from the world by way of the 'getObjects' method. If you only have one Mnim instance in the world, you can just use:
removeObjects(getObjects(Mnim.class));
This will remove any and all Mnim instances from the world.
KiwiMC1482 KiwiMC1482

2015/3/9

#
I think i understand what your saying but there will be 8 minims in the world at any one time max and i'm trying to delete them all at once would i still use the same code or is there a different way to do it?
danpost danpost

2015/3/9

#
KiwiMC1482 wrote...
I think i understand what your saying but there will be 8 minims in the world at any one time max and i'm trying to delete them all at once would i still use the same code or is there a different way to do it?
Read the last line of my previous post.
KiwiMC1482 KiwiMC1482

2015/3/11

#
I'm having a little trouble with the syntax for the if statement so when backspace is pressed it removes the minim I put what you'd expect like if("backspace.equals(Greenfoot.getKey() etc but it doesn't seem to be working for me
danpost danpost

2015/3/11

#
KiwiMC1482 wrote...
I'm having a little trouble with the syntax for the if statement so when backspace is pressed it removes the minim I put what you'd expect like if("backspace.equals(Greenfoot.getKey() etc but it doesn't seem to be working for me
You should copy/paste your code into your posts using the code link below the reply box. When syntax is involved, it is even more important that you show what you are actually using -- exactly.
You need to login to post a reply.