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

2019/12/30

A question. how to remove

Zwemvis Zwemvis

2019/12/30

#
Hoi Greenfoot users. I have to ask a question. How to put a instruction in the World/Actor to remove something that is not yet in the world, but later will be...... Now i get an error, when i enter the code. Alvast bedankt voor de de medewerking. Groet Ruard
danpost danpost

2019/12/30

#
Zwemvis wrote...
Hoi Greenfoot users. I have to ask a question. How to put a instruction in the World/Actor to remove something that is not yet in the world, but later will be...... Now i get an error, when i enter the code.
What error? -- What code? To remove something (at some point) that may or may not be in the world, you can still request it be removed with:
Actor something = ???; // the actor to remove

removeObject(something); // in World subclass
// or
getWorld().removeObject(something); // in Actor subclass
Zwemvis Zwemvis

2019/12/30

#
the error is " cannot find symbol variable Fire", if i put the code removeObejct(Fire); in the World subclass or getWorld().removeObejct(Fire); in the Actor subclass. I want to put a message on the screen, and after 10 seconds remove it again.
danpost danpost

2019/12/30

#
Zwemvis wrote...
the error is " cannot find symbol variable Fire", if i put the code removeObejct(Fire); in the World subclass or getWorld().removeObejct(Fire); in the Actor subclass. I want to put a message on the screen, and after 10 seconds remove it again.
I must presume that Fire is a class name -- not a variable that is an Object reference to an instance of the Fire class (an actor created from the Fire class). A class (an Object of type Class) is never in a world -- only Actor instances are. Still, not enough code has been provided to afford any assistance.
Zwemvis Zwemvis

2019/12/30

#
you are right. Fire is a class name, but wen i put in de code, it will gives the error that I described above. this is part of code i am talking about. public void raakBlad() { MyWorld myWorld = (MyWorld)getWorld(); if(isTouching(Blad1.class)) { if (vuur == 1){ myWorld.addObject(new Fire(200,200),300,200); imageCounter = (++imageCounter)%20; myWorld.removeObject(Fire); vuur = 0; } } } Thanks for the support.
danpost danpost

2019/12/30

#
Zwemvis wrote...
you are right. Fire is a class name, but wen i put in de code, it will gives the error that I described above. this is part of code i am talking about. << Code Omitted >>
Move counter and code to remove Fire instance to the Fire class. Use:
getWorld().removeObject(this);
Zwemvis Zwemvis

2019/12/31

#
Hoi Danpost Thanks for your help :-) Bedankt voor je hulp.
You need to login to post a reply.