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

2020/5/14

I need some help

1
2
danpost danpost

2020/5/15

#
Change line 14 to an "else if" line.
Juniper Juniper

2020/5/15

#
That stopped the extra counting whenever a block is clicked, but whenever "null" is clicked, it still adds 3. Also the NullPointerException still exists
danpost danpost

2020/5/15

#
Juniper wrote...
That stopped the extra counting whenever a block is clicked, but whenever "null" is clicked, it still adds 3. Also the NullPointerException still exists
Okay. That is because you have (initially) 3 blocks in your world and each one is registering a miss (and when one is clicked on, two register a miss). Move the click detection code to your MyWorld class (it can have an act method also).
Juniper Juniper

2020/5/15

#
Oh my god that is brilliant. I feel so stupid. How do I identify between the blocks if they're not identified by currentBlock = "this" I refuse to make multiple classes for all 3 blocks; however if I must, then I will
danpost danpost

2020/5/15

#
Juniper wrote...
Oh my god that is brilliant. I feel so stupid. How do I identify between the blocks if they're not identified by currentBlock = "this" I refuse to make multiple classes for all 3 blocks; however if I must, then I will
If click detected AND mouse actor is not null AND mouse actor is an instance of block class, then ...
Juniper Juniper

2020/5/18

#
Could I request some sample code? I've got the click detection part, but after that, I don't really understand. Please forgive my ignorance.
danpost danpost

2020/5/18

#
Juniper wrote...
Could I request some sample code? I've got the click detection part, but after that, I don't really understand. Please forgive my ignorance.
if (Greenfoot.mouseClicked(null))
{
    MouseInfo m = Greenfoot.getMouseInfo();
    Actor mA = m.getActor();
    if (mA != null && (mA instanceof block)) Click++; else Miss++;
    totalClicked++;
    calcTotal();
    calcAcc();
}
Juniper Juniper

2020/5/19

#
Thank you. I have managed to get it to work absolutely perfectly. Much appreciated!
You need to login to post a reply.
1
2