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

Username:   Password: 
 RegisterRegister   
 I NEED HELP w/mousewhere
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
lavamonkey




PostPosted: Wed Apr 20, 2016 1:33 pm   Post subject: I NEED HELP w/mousewhere

I require urgent help with my code. My goal is to have the oval stop when I click on it in less than 10 seconds. I am a new coder and need some help with this task. I can't find my mistake. I will be eternally grateful for who ever can help me.

setscreen ("graphics:800;500")

var m, n, mx, my, button : int
var score : int := 0


for i : 1..10
mousewhere (mx, my, button)
drawfillbox (0, 0, maxx, maxy, white)
m := Rand.Int (50, 700)
n := Rand.Int (50, 400)
drawfilloval (m, n, 30, 30, black)

if (mx > m - 15) and (mx < m + 15) and (my > n - 15) and (my < n + 15) and (button = 1) then
score := score + 1
end if
delay (1000)
exit when score = 1

end for
cls
put "anything"
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Wed Apr 20, 2016 11:35 pm   Post subject: RE:I NEED HELP w/mousewhere

Your code seems mostly correct (you check rectangular bounds correctly, you make decent use of variables, etc). However, your loop does this:

1. Get the mouse location at this very instant.
2. Draw the box the user is supposed to click on.
3. Check whether the user was already holding down the mouse button on that location.
4. Wait for 1 second, without ever checking the mouse again.

What do you think is the problem with that?

(and, in the future, please include information about what you expected vs what actually happens -- like "it doesn't seem to register when I click on the oval; I expected it to increase my score and exit the loop.")
lavamonkey




PostPosted: Thu Apr 21, 2016 1:49 pm   Post subject: RE:I NEED HELP w/mousewhere

I believe the problem is with the initial mouse location. I think it just registers that mouse location and nothing else after that.

I was expecting the ovals to pop at random locations and when you click on it, the program would exit the loop and cls and display anything.

Can you tell me what my problem is and how to fix it?

Thanks
Insectoid




PostPosted: Thu Apr 21, 2016 3:39 pm   Post subject: RE:I NEED HELP w/mousewhere

It registers exactly ten mouse locations. Can you figure out why?

mouse commands, games and animations generally don't work very well with long delays. Your delay should only be 5-10ms. That's only part of the solution.
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 1  [ 4 Posts ]
Jump to:   


Style:  
Search: