Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Can't get mousewait to work :(
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
chroncile




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: 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.
chroncile




PostPosted: 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 Sad
Tony




PostPosted: 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 Wink
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
chroncile




PostPosted: Thu Dec 11, 2008 11:00 am   Post subject: RE:Can\'t get mousewait to work :(

I don't understand. Please help me Sad
Tony




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
chroncile




PostPosted: 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. Sad
Tony




PostPosted: 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?
Turing:

mousewhere (x, y, button)
exit when button = 1 and x >= x1 and x <= x2 and y >= y1 and y <= y2
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
chroncile




PostPosted: 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.
Tony




PostPosted: 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...
Turing:

mousewhere (x, y, button)
locate(1,1)
put "Your mouse is at: ", x, " : ", y
put "Your box is between: ", x1, ":", y1, " and ", x2, ":",y2
exit when button = 1 and x >= x1 and x <= x2 and y >= y1 and y <= y2
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
chroncile




PostPosted: 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?
Tony




PostPosted: 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).
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
chroncile




PostPosted: Thu Dec 11, 2008 1:38 pm   Post subject: RE:Can\'t get mousewait to work :(

Yes it was.
Tony




PostPosted: Thu Dec 11, 2008 1:45 pm   Post subject: RE:Can\'t get mousewait to work :(

No.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
chroncile




PostPosted: 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. Very Happy
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 16 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: