Mouse buffer?
Author |
Message |
MysticVegeta
![](http://www.geocities.com/ohsoinsane/my_avatar.JPG)
|
Posted: Fri Jul 21, 2006 8:22 pm Post subject: Mouse buffer? |
|
|
I cant help but have this thing really **** me off.
code: |
loop
mousewhere (x, y, z)
if z = 1 then
put "crap"
end if
if z = 1 then
put "crap2"
end if
end loop
|
Hmm, it seems to output:
crap
crap2
crap
crap2
crap
crap2
But, I want to clear the mouse buffer asa it enters one of the if structures so that it doesnt enter the second one. I know Input.Flush clears the keyboard buffer, is there some sort of command for the mouse one, I cant seem to find it. or do I have to recreate it? Thanks for the hep guys ![Smile Smile](http://compsci.ca/v3/images/smiles/icon_smile.gif) |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Mazer
![](http://compsci.ca/v3/uploads/user_avatars/1323750815476d9f446d80c.png)
|
Posted: Fri Jul 21, 2006 9:20 pm Post subject: (No subject) |
|
|
Maybe you should look up the other mouse commands (mousebuttonmoved or something like that), and check for a click and release of the button instead of just checking if it's pressed. |
|
|
|
|
![](images/spacer.gif) |
[Gandalf]
![](http://compsci.ca/v3/uploads/user_avatars/189297994e4c716fec7f1.png)
|
Posted: Sat Jul 22, 2006 1:08 am Post subject: (No subject) |
|
|
I don't get your problem... If you don't want the second if structure to be entered, then why have the second if z = 1 then there in the first place? |
|
|
|
|
![](images/spacer.gif) |
NikG
|
Posted: Sat Jul 22, 2006 2:00 am Post subject: (No subject) |
|
|
With that code, your output will always be crap crap2 crap crap2...
Think about it, the z value only gets updated in the mousewhere proc (use Mouse.Where btw). So once it notices a click, the z will be 1 so both if statements will always be true until mousewhere turns it back to 0.
Now as far as a buffer, I believe there isn't one. As mazer suggested, look up Mouse.ButtonMoved and/or Mouse.ButtonWait |
|
|
|
|
![](images/spacer.gif) |
NikG
|
Posted: Sat Jul 22, 2006 2:10 am Post subject: (No subject) |
|
|
(sorry for the double post)
Another solution (although this doesn't help with your 2 ifs) is to add another variable which prevents holding the mouse button down: code: | var x, y, z, z2 : int
z := 0
loop
z2 := z
mousewhere (x, y, z)
if z = 1 and z2 = 0 then
put "crap"
end if
% if z = 1 then
% put "crap2"
% end if
delay (100)
cls
end loop |
(Note: code untested) |
|
|
|
|
![](images/spacer.gif) |
Windsurfer
![](http://photo-origin.tickle.com/image/118/9/8/O/118982819O270687078.jpg)
|
Posted: Sun Jul 23, 2006 1:14 pm Post subject: (No subject) |
|
|
Or, you could make a function.
code: |
function MouseClicked : boolean
var x, y, z : int
Mouse.Where (x, y, z)
if z = 1 then
result true
else
result false
end if
end MouseClicked
|
You can use the above function by simply making an if statement, where it will procede to (essentially) clear the mouse buffer and find out if a button is being pressed. |
|
|
|
|
![](images/spacer.gif) |
MysticVegeta
![](http://www.geocities.com/ohsoinsane/my_avatar.JPG)
|
Posted: Sun Jul 23, 2006 1:44 pm Post subject: (No subject) |
|
|
Ok, Heres a better explanation of the problem, I know the first one was crappy.
Here is the mousewhere in the form of keyboard input.
code: | loop
if hasch then
put "crap"
%Input.Flush
end if
if hasch then
put "crap2"
%Input.Flush
end if
end loop
|
same output, crap, crap2, crap, crap2.....
Uncommment Input.Flush. Even though both if's are same "if hasch then". It only enters one of them. Thats what I want for the mousewhere. But this problem is no concern to me now, I used booleans to do it instead. |
|
|
|
|
![](images/spacer.gif) |
Mazer
![](http://compsci.ca/v3/uploads/user_avatars/1323750815476d9f446d80c.png)
|
Posted: Mon Jul 24, 2006 7:23 am Post subject: (No subject) |
|
|
May I ask what this is for? Like, a game, maybe? |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
MysticVegeta
![](http://www.geocities.com/ohsoinsane/my_avatar.JPG)
|
Posted: Mon Jul 24, 2006 10:05 am Post subject: (No subject) |
|
|
Yes thats correct. Its for chess. I needed that because once when you click a piece, it gets selected, the next time to click on the location it can move, it moves there, but it used to enter both of the statements at the same time. I didnt want to create one more loop inside the first if, so I wondered about mouse buffer, but I accomplished the task using booleans instead. |
|
|
|
|
![](images/spacer.gif) |
[Gandalf]
![](http://compsci.ca/v3/uploads/user_avatars/189297994e4c716fec7f1.png)
|
Posted: Mon Jul 24, 2006 4:59 pm Post subject: (No subject) |
|
|
Which really is the right way of going about things...
A proper loop structure takes input from each source once per iteration, same as with View.Update, delays, and all those other things. The performance of your if hasch then... if hasch then... example would highly depend on the speed at which each section was executed. You should be looking for more control over your programs flow.
Chess? Aww shucks. I should spiff mine up and release it before it doesn't seem like anything special. ![Sad Sad](http://compsci.ca/v3/images/smiles/icon_sad.gif) |
|
|
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Mon Jul 24, 2006 7:27 pm Post subject: Re: Mouse buffer? |
|
|
Guys, slow down a minute. Take a step back; look at the original question.
MysticVegeta wrote: I cant help but have this thing really **** me off.
code: |
loop
mousewhere (x, y, z)
if z = 1 then
put "crap"
end if
if z = 1 then
put "crap2"
end if
end loop
|
Hmm, it seems to output:
crap
crap2
crap
crap2
crap
crap2
But, I want to clear the mouse buffer asa it enters one of the if structures so that it doesnt enter the second one. I know Input.Flush clears the keyboard buffer, is there some sort of command for the mouse one, I cant seem to find it. or do I have to recreate it? Thanks for the hep guys ![Smile Smile](http://compsci.ca/v3/images/smiles/icon_smile.gif)
We want to make it so that the button is no longer clicked, in essence. The button is not down when z = 0. So, set z to zero.
code: |
var x, y, z : int
loop
mousewhere (x, y, z)
if z = 1 then
put "crap"
z := 0
end if
if z = 1 then
put "crap2"
end if
end loop
|
z is just a variable. We have complete control over it.
No need to use hope for fancy things like a mouse version of Input.Flush. |
|
|
|
|
![](images/spacer.gif) |
Mazer
![](http://compsci.ca/v3/uploads/user_avatars/1323750815476d9f446d80c.png)
|
Posted: Mon Jul 24, 2006 8:32 pm Post subject: (No subject) |
|
|
I'm more concerned with the reason it's being used. Consider the following (/me does Bill Nye head shaking thing)
code: | loop
if hasch then
delay (1500)
put "asd"
end if
end loop
|
If you press a key once, it will output "asd" every ~1.5 seconds. That's what Input.Flush is for. It will clear the buffer, so that next time you go through the loop, you aren't worrying about whether a key was pressed last time.
code: | loop
mousewhere (x, y, z)
if z = 1 then
put "crap"
end if
if z = 1 then
put "crap2"
end if
end loop |
To me, it doesn't really make sense to want to clear a buffer. You can't possibly expect somebody to press a mouse button only from the mousewhere line to the end of the first if statement. Of course, I don't know if MysticVegeta's program looked anything like that, it's just the example that, uh... it... Hey, Delos! I need a word for "bothered!"
But anyways, I guess the problem is already solved. |
|
|
|
|
![](images/spacer.gif) |
Delos
![](http://www.members.shaw.ca/rfolz/delos_avatar.gif)
|
Posted: Tue Jul 25, 2006 9:04 am Post subject: (No subject) |
|
|
/me shakes head...
"irked", "inflamed", "jived", "beset", "annoyed", "badgered", ("badger badger badger badger badger badger badger badger badger badger badger badger mushroom mushroom"), "molested", "perturbed", "ingratiated", "pested", "follied", "upset", "ruffled", "flustered", "troubled", "mentally fondled"...
Take your pick. |
|
|
|
|
![](images/spacer.gif) |
Mazer
![](http://compsci.ca/v3/uploads/user_avatars/1323750815476d9f446d80c.png)
|
Posted: Tue Jul 25, 2006 1:23 pm Post subject: (No subject) |
|
|
Y'know, I was thinking "irked" when I wrote the post, but I like "ruffled" better. Thanks!
PS: I'm fairly certain you've got an extra "badger" in there. I'll check again, but IIRC the ratio is eleven badgers to two mushrooms. (Can't remember the badger/mushroom to snake ratio, though). |
|
|
|
|
![](images/spacer.gif) |
MysticVegeta
![](http://www.geocities.com/ohsoinsane/my_avatar.JPG)
|
Posted: Tue Jul 25, 2006 3:57 pm Post subject: Re: Mouse buffer? |
|
|
Cervantes wrote: Guys, slow down a minute. Take a step back; look at the original question.
MysticVegeta wrote: I cant help but have this thing really **** me off.
code: |
loop
mousewhere (x, y, z)
if z = 1 then
put "crap"
end if
if z = 1 then
put "crap2"
end if
end loop
|
Hmm, it seems to output:
crap
crap2
crap
crap2
crap
crap2
But, I want to clear the mouse buffer asa it enters one of the if structures so that it doesnt enter the second one. I know Input.Flush clears the keyboard buffer, is there some sort of command for the mouse one, I cant seem to find it. or do I have to recreate it? Thanks for the hep guys ![Smile Smile](http://compsci.ca/v3/images/smiles/icon_smile.gif)
We want to make it so that the button is no longer clicked, in essence. The button is not down when z = 0. So, set z to zero.
code: |
var x, y, z : int
loop
mousewhere (x, y, z)
if z = 1 then
put "crap"
z := 0
end if
if z = 1 then
put "crap2"
end if
end loop
|
z is just a variable. We have complete control over it.
No need to use hope for fancy things like a mouse version of Input.Flush.
You, my friend, are a genius! What the hell was I thinking? LOL, completely didnt look at the part where I could set it back to 0. I always thought of those variables as pointers and couldnt be changed (like the arguments of the functions, we cant change them once we are inside the fucntion, although in other langs we can) This gets me rid of a 4 line long if structure and a boolean! woot more memory free! Thanks a lot, I never thought of it that way, I am still shocked, O_O. |
|
|
|
|
![](images/spacer.gif) |
|
|