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

2016/1/10

Mouse info

1
2
TentaBreak TentaBreak

2016/1/20

#
Okay, thanks. And yeah, the return thing makes sense, I don't know why I didn't get it sooner lol, anyway. when I removed the "return" by the end of 8 line, I could click on everything and it would be gone. So that fixed something. Also, I need to get the .getValue() code to be able to compare classes? And am I supposed to get int aswel? I don't know what am I supposed to do else, it keeps saying "cannot find method" or something with boolean and "incomparible types". I don't know what to do with line 15, I understand to compare the classes but I don't know which code should I use to properly compare them and if they match, they're gone. And yes, my mistake about the removeObjects and adding them. I was trying the code to work and I put them under the comment, I wasn't paying enough attention and deleted them. But still it should remove one of them, right? Anyway, the code is this:
    private Actor firstClick;
   // Monkey m1 = new Monkey(); these are defined at the very beggining
   // Banana b1 = new Banana();
    
    public void act()
     {
      if (Greenfoot.mouseClicked(null))
      {
          MouseInfo mouse = Greenfoot.getMouseInfo();
          Actor mouseActor = mouse.getActor();
          if (mouseActor == null || mouseActor instanceof Banana);
            removeObject(b1);
         if ( firstClick == null)
          {
             firstClick = mouseActor;
           }
           if ( code )
           {
               removeObject(m1);
               removeObject(b1);
           }
           else
           {
                addObject(m1, 671, 89);
                addObject(b1,216, 324); 
            } 
            firstClick = null;
        }
}
 
danpost danpost

2016/1/20

#
Just remove lines 2 and 3. The object (monkey or banana) first clicked on will be stored in 'firstClick' (the second clicked on object will be in 'mouseActor'). Remove line 12. You should not be removing anything by itself (and certainly not without knowing if it was the first or second object clicked on). The condition on line 11 is incomplete (it should also check the possibility that the clicked on object is a Monkey instance). Also, with line 11, it should not have a semi-colon at the end and all following code should be within its block (curly brackets which are missing). Lines 17 through 21 need to replace lines 24 and 25 and adjusted appropriately to check that 'firstClicked' and 'mouseActor' are one Banana and one Monkey object and then they be removed if so.
TentaBreak TentaBreak

2016/1/20

#
Okay.. For now I will leave line 11 as it is ( Monkey being clicked first).. and after line 17, should this do then? And in comparing the classes I keep getting errors, what code must I use? I keep getting either : incompatible types or cannot find method. I looked at some other codes and I even inserted .getValue(), and called it and everything, and still got a problem " cannot find method ". Less than a week to finish the game, and I have no idea how what code to use to compare classes.

       if ( firstClick == null)
          {
             firstClick = mouseActor;
        }
           else
           {
           if ( //Still don't know. Keep getting errors. )
           {
               removeObject(mouseActor);
               removeObject(firstClick);
           }
           else
           {
                addObject(firstClick, 671, 89);
                addObject(mouseActor,216, 324); 
            } 
            firstClick = null;
    }

danpost danpost

2016/1/20

#
You cannot leave line 11 in your earlier post unchanged. Either it should not check for either type actor (Monkey or Banana instance) or it must check for both. If not checking for either, then you would then check for each type in the later conditional ifs (lines 1 and 7 in your last post). For now -- at least remove lines 12 through 16 in the last post from your code.
You need to login to post a reply.
1
2