Computer Science Canada Can't get mousewait to work :( |
Author: | chroncile [ Wed Dec 10, 2008 11:22 pm ] |
Post subject: | Can't get mousewait to work :( |
Hi, I have another assignment and I'm suppose to make a game using mousewait and this is my code so far: Quote: % Declares Integers % x: Where the user has clicked - x coordinate % y: Where the user has clicked - y coordinate % button: determine whether the mouse has been clicked or % not and which button has been clicked % x1, y1, x2, and y2 are randomized integers for a box % c1 is a randomized integer for colour var x, y, button : int var x1, y1, x2, y2, c1 : int % Display a message put "Click the box to win!" loop cls randint (x1, 30, 75) randint (y1, 30, 75) randint (x2, 30, 75) randint (y2, 30, 75) randint (c1, 1, maxcolour) drawfillbox (x1, y1, x2, y2, c1) mousewhere (x, y, button) exit when button = 1 and x >= x1 and x <= x2 and y >= y1 and y <= y2 delay (2000) put "Sorry, try again." delay (1000) end loop put "Congratulations, you win!" The thing is, it doesn't work; it's suppose to exit when the user has clicked in the box, but it's not doing that. Can anyone tell me what I am doing wrong? Thanks - chroncile |
Author: | DemonWasp [ Thu Dec 11, 2008 1:14 am ] |
Post subject: | RE:Can\'t get mousewait to work :( |
You seem to be re-randomising the location of the box (x1, y1, x2, y2), clearing the screen, and redrawing the box, on every iteration of the loop. You only want to do that once, before the loop begins. |
Author: | chroncile [ Thu Dec 11, 2008 10:07 am ] |
Post subject: | RE:Can\'t get mousewait to work :( |
No no no, I need to do that because the game puts the box randomly on the screen and if I were to do that, it wouldn't work |
Author: | Tony [ Thu Dec 11, 2008 10:39 am ] |
Post subject: | RE:Can\'t get mousewait to work :( |
The code is doing exactly what it is told (read it slowly, one line at a time). You are just not clicking fast enough |
Author: | chroncile [ Thu Dec 11, 2008 11:00 am ] |
Post subject: | RE:Can\'t get mousewait to work :( |
I don't understand. Please help me |
Author: | Tony [ Thu Dec 11, 2008 11:20 am ] |
Post subject: | RE:Can\'t get mousewait to work :( |
You are not clicking fast enough, before the position of the box changes. Right after you record mouse position and state, you might want to draw something in that location, to help you visually compare that, to your box. |
Author: | chroncile [ Thu Dec 11, 2008 11:42 am ] |
Post subject: | RE:Can\'t get mousewait to work :( |
I am clicking fast enough. I don't understand what you are talking about. |
Author: | Tony [ Thu Dec 11, 2008 12:05 pm ] | ||
Post subject: | RE:Can\'t get mousewait to work :( | ||
how much time passes between those two statements, in your program?
|
Author: | chroncile [ Thu Dec 11, 2008 12:13 pm ] |
Post subject: | RE:Can\'t get mousewait to work :( |
Okay, I made it like this: mousewhere (x, y, button) delay (1000) exit when button = 1 and x >= x1 and x <= x2 and y >= y1 and y <= y2 But it's still not working. |
Author: | Tony [ Thu Dec 11, 2008 12:56 pm ] | ||
Post subject: | RE:Can\'t get mousewait to work :( | ||
clearly, you fail to grasp what mousewhere does. Go back and re-read class notes / documentation / tutorials available on this website. In the meantime...
|
Author: | chroncile [ Thu Dec 11, 2008 1:03 pm ] |
Post subject: | RE:Can\'t get mousewait to work :( |
Thanks for that, but the problem is that it's still not working. I clicked inside the box and it didn't work. You say it's working, but how come it's not doing that for me? |
Author: | Tony [ Thu Dec 11, 2008 1:23 pm ] |
Post subject: | Re: RE:Can\'t get mousewait to work :( |
chroncile @ Thu Dec 11, 2008 1:03 pm wrote: I clicked inside the box and it didn't work.
Yes, but was your program recording the status of your mouse at that instance? You are using mousewhere just once (per each box location) -- if your mouse is not over the box at the same moment as it's created, then it's not going to work. Perhaps you should check the status of the mouse more than once, preferably over some range of time (instead of a point). |
Author: | chroncile [ Thu Dec 11, 2008 1:38 pm ] |
Post subject: | RE:Can\'t get mousewait to work :( |
Yes it was. |
Author: | Tony [ Thu Dec 11, 2008 1:45 pm ] |
Post subject: | RE:Can\'t get mousewait to work :( |
No. |
Author: | chroncile [ Thu Dec 11, 2008 1:49 pm ] |
Post subject: | RE:Can\'t get mousewait to work :( |
Haha, look I don't understand this. Please teach me and end it. |
Author: | DanielG [ Thu Dec 11, 2008 9:50 pm ] | ||||
Post subject: | Re: Can't get mousewait to work :( | ||||
each time you call mousewhere, turing records the variables, they are not constantly changing. In your code, when you are writing:
you are getting the position and click value of the mouse right after the box is made, and only once. also, immediately afterward you check the value of the buttons, the delay (2000) is useless here in terms of giving time for the user to click in the box. instead you should do something like this:
note that the above isn't exactly correct code (meaning you shouldn't copy and paste it into yours, however, it should give you the general Idea of what you need to change in your code. |