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

2012/1/12

Duplicating Actors?

Nate Nate

2012/1/12

#
In my program, I am trying to add an actor in order to remove some other objects in the program. The problem, however, is that whenever I run the program and click on the object, it duplicates the object instead of running the method attached. Any ideas as to why this is happening?
//This is what it should do when I click the object "start"
        else if(Greenfoot.mouseClicked(start)){
            removeObject(g1);
            removeObject(g2);
            removeObject(g3);
        }
davmac davmac

2012/1/12

#
It's impossible to say without seeing more of your code.
Duta Duta

2012/1/12

#
What @davmac said, however its possible that earlier in the 'if -> else if -> else if -> (etc) -> else' statements, that something earlier on in it is true, meaning that that if statement is being executed (presumably something that creates another of the object), which means, because that section of code you put up there is an 'else if' rather than an 'if', it does not get executed. That might not be the clearest thing, so I'll try to express it in code:
int a = 0;
if(a == 0) //which is true
{
    addObject(g1); //or something
}
else if(Greenfoot.mouseClicked(start)) //even if this is true, it will not be executed due to the first if statement being executed
{
    removeObject(g1);
    removeObject(g2);
    removeObject(g3);
}
I might be on the wrong track here, however its just a possibility
Nate Nate

2012/1/12

#
Hey, I figured it out. Apparently that particular piece of code needed to be in the original "if" statement in order for it to work. I have no idea why that is seeing as my other buttons worked fine. Oh well.
Duta Duta

2012/1/13

#
Nate wrote...
Hey, I figured it out. Apparently that particular piece of code needed to be in the original "if" statement in order for it to work. I have no idea why that is seeing as my other buttons worked fine. Oh well.
Maybe because of what I said?
You need to login to post a reply.