This site requires JavaScript, please enable it in your browser!
Greenfoot back
Back to discussions
USER_NAME
USER_NAME wrote ...

2017/4/21

How to add counter, I have imported class counter (New to greenfoot)

USER_NAME USER_NAME

2017/4/21

#
Hi, Can you tell me how to add the code for the counter or create an actor that adds 1 every time one actor touches the other actor. The scoreboard needs to display the value reached. Thank you, USER_NAME
danpost danpost

2017/4/21

#
USER_NAME wrote...
how to add the code for the counter or create an actor that adds 1 every time one actor touches the other actor. The scoreboard needs to display the value reached.
Please stick to one thing at a time -- like getting a working counter to begin with. The JOC videos (#16) explains how to implement the counter.
USER_NAME USER_NAME

4 days ago

#
Hello Danpost, nice to meet you. I just got finished with a game of chess, I am back now. I am trying to get the counter working using the imported counter.My game consists of a mouse eating cheese,the cheese moves around as you chase it, then the mouse will eat said cheese.I need the counter to add one point everytime it eats some cheese. I will check out the JOC vids. Thanks, I am off to play some SuDoku Puzzles now.
ChessMaster123 ChessMaster123

4 days ago

#
Why hello fellow chess players, I am also struggling with making a counter work and I would really appreciate some help. Thanks!
USER_NAME USER_NAME

4 days ago

#
The video posted onto youtube (Joy of code #16) is very quiet and i cannot hear the man speaking. Oh, Hi fellow chess player. Thanks, USER_NAME
ChessMaster123 ChessMaster123

4 days ago

#
I have had similar issues to you Mr. USER_NAME, The JOC videos are very quiet and I think my hearing aid is a bit faulty.
danpost danpost

4 days ago

#
USER_NAME wrote...
Hello Danpost, nice to meet you. I just got finished with a game of chess, ... I am off to play some SuDoku Puzzles now.
Hi fellow chess players: Billards, chess and Sudoku are some of my favorites. Fastest Sudoku with my Sudoku scenario here on the site is 2m 3s -- avg between 5-6m. I also have a couple of Chess scenarios here on the site (one, more towards learning the game, the other, more for playing).
I am trying to get the counter working using the imported counter.My game consists of a mouse eating cheese,the cheese moves around as you chase it, then the mouse will eat said cheese.I need the counter to add one point everytime it eats some cheese.
Something like this should work:
if (isTouching(Cheese.class))
{
    removeTouching(Cheese.class);
    ((MyWorld)getWorld()).getCounter().add(1);
}
If you still are having issues, start by posting your World subclass codes.
USER_NAME USER_NAME

3 days ago

#
Hi, Thanks for the recommendation on the games, which I will check out,I have added the lines you have supplied into my subclass, and it works.I just need to check if it meets requirements. Many thanks, User_name
ChessMaster123 ChessMaster123

3 days ago

#
Wow! Thanks guys! It really worked you really saved me! Maybe we could play chess some time.
You need to login to post a reply.