Computer Science Canada Need help with a high score program |
Author: | whathaveidone [ Fri Jun 14, 2013 1:59 pm ] |
Post subject: | Need help with a high score program |
What is it you are trying to achieve? <Create a working program that counts the amount of times a box has been clicked then records and organizes the data into a high score table> What is the problem you are having? <Can't get the counter to work.> Describe what you have tried to solve this problem <Got a friend that is better at turing than I am (We both are inexperienced with programming) he added a bunch of code that just further confused me and I am not really sure what to do.> Please specify what version of Turing you are using <4.1> |
Author: | Zren [ Fri Jun 14, 2013 2:46 pm ] |
Post subject: | RE:Need help with a high score program |
Quote: <Can't get the counter to work.>
Which counter exactly? ~ procedure AAA procedure AAB var f1 : int Try to be more descriptive when naming variables/functions/things. Giving something a good name will make it easier for someone fresh to the code. ~ When learning something new (like file input/output), start a new program. Then, once you're familiar with the tools used, merge them into other programs. |
Author: | whathaveidone [ Mon Jun 17, 2013 12:34 pm ] |
Post subject: | Re: RE:Need help with a high score program |
Zren @ Fri Jun 14, 2013 2:46 pm wrote: Quote: <Can't get the counter to work.>
Which counter exactly? ~ procedure AAA procedure AAB var f1 : int Try to be more descriptive when naming variables/functions/things. Giving something a good name will make it easier for someone fresh to the code. ~ When learning something new (like file input/output), start a new program. Then, once you're familiar with the tools used, merge them into other programs. Procedure AAA is the timer I was originally going to use but then I decided that the program should end when the box reaches its destination instead so I guess it is rather useless. AAB is the procedure containing the box's movement around the screen. And I am not really sure what the variable f1 represents, all the highscore stuff was added in by a friend so I am not really sure what it represents. I am guessing that this code isn't salvageable and I should probably just start a new one right? |
Author: | whathaveidone [ Mon Jun 17, 2013 12:47 pm ] | ||||
Post subject: | Re: Need help with a high score program | ||||
After editing out some of the useless stuff I was able to get to the highscore table that my friend made which gets rid of that problem yet I still am not sure how to get it so that when you click the sprite it adds to the score. Can anyone identify the problem here?
Mod Edit: Please wrap you code in either of the following in order to preserve whitespace (indentation) and to highlight the syntax.
|
Author: | Zren [ Mon Jun 17, 2013 10:21 pm ] | ||
Post subject: | RE:Need help with a high score program | ||
Your code needs way more comments.
Notice how similar that code is? Perhaps you should move a single loop into a procedure, then have parameters for the things that are different. ~ So far as I can see, you are not saving (writing to file) the highscores. You ARE repeating code to read the highscores both at the begining before the... boxes move across the screen, and after you've sorted the highscores. Repeated code should go inside a procedure. Check out the File I/O tutorial in the Turing Walkthrough to learn how to save the highscores. http://compsci.ca/v3/viewtopic.php?t=12972 ~ Which "sprite" are you talking about? Are you talking about the box moving across the screen? If I understand the code correctly, it is already incrementing the score if the mouse is over the box, regardless of the button state. If you want it to increment the score only when a mouse button is DOWN then you also need to compare mouse_b as well. If you want to only increment the score when the mouse has been clicked (pushed down, then released) then you need to remember the last button state and compare that as well. ~ var x, y, b : int With context, we know that these refer to the mouse x,y and button state. However you use "x" and "y" elsewhere in the program to refer to other coordinates, so specifying them as mouse_x, mouse_y, mouse_b helps lessen the ambiguity. |