click counter- revised
Author |
Message |
neverstopbelevin
|
Posted: Thu Nov 18, 2010 5:22 pm Post subject: click counter- revised |
|
|
i need to make a click counter
i have the following code, however when i run it it continues adding until i stop clicking.
for example 1..infinity.
how do i get it to count 1 click?
run the code below if you dont understand what im trying to communicate
code: |
var mx, my, mb : int
var c : int := 0
loop
mousewhere (mx, my, mb)
if mb = 1
then
c := c + 1
put c
end if
end loop
| [/code] |
|
|
|
|
|
Sponsor Sponsor
|
|
|
TokenHerbz
|
Posted: Thu Nov 18, 2010 5:54 pm Post subject: RE:click counter- revised |
|
|
i guess you could add a boolean so you know if you've counted the click already, so it wont constantly add to your counter while you hold down the mouse click. |
|
|
|
|
|
TerranceN
|
Posted: Thu Nov 18, 2010 5:55 pm Post subject: RE:click counter- revised |
|
|
You can tell when someone has just clicked because the mouse button changed from 0 to 1. So just store the previous mouse button and check if the mouse button is down now, but wasn't last frame. |
|
|
|
|
|
TokenHerbz
|
Posted: Thu Nov 18, 2010 6:06 pm Post subject: RE:click counter- revised |
|
|
try my way first and post the code. its good to learn about booleans, this example fits it well. |
|
|
|
|
|
neverstopbelevin
|
Posted: Thu Nov 18, 2010 6:10 pm Post subject: RE:click counter- revised |
|
|
token, i would try what you said, if i knew what you were saying lol
ive got limited turing knowledge |
|
|
|
|
|
TerranceN
|
Posted: Thu Nov 18, 2010 6:19 pm Post subject: RE:click counter- revised |
|
|
A boolean is a variable that can have two values, either true or false.
You can declare it like
Turing: |
var hasClickBeenCounted : boolean := false
|
The names for booleans are usually written so that it is like asking a question that would get a true or false answer, implying that it is a boolean value.
As for using this type of variable to solve your problem, when you detect that the mouse is down and hasBeenClicked is set to false, you count a click and set it to true, therefore no more clicks will be registered.
But you have to make sure that when the mouse is not being pressed you set hasBeenClicked to false, allowing you to register a click once again when the mouse is pressed. |
|
|
|
|
|
TokenHerbz
|
Posted: Thu Nov 18, 2010 6:21 pm Post subject: RE:click counter- revised |
|
|
booleans are either, true or false.
you declare one like :
code: |
var checksomething: boolean := false
|
then with that, you want to assign it to clicking, so when you click once, you know if you counted it or not. then when your clicking is done, it goes back to false. use some if statements to set that up, and it will stop your continuous counting.
basic setup:
code: |
if mouse clicked then %%mouse is clicked
if check boolean = false then %%this click not counted
counter adds 1 %%add to counter
set check boolean to true %%stops counting for this click
end if
end if
if mouse not clicked then
we can set boolean to false again
end if
|
|
|
|
|
|
|
neverstopbelevin
|
Posted: Thu Nov 18, 2010 6:26 pm Post subject: RE:click counter- revised |
|
|
can someone just write the code |
|
|
|
|
|
Sponsor Sponsor
|
|
|
TheGuardian001
|
Posted: Thu Nov 18, 2010 7:48 pm Post subject: Re: RE:click counter- revised |
|
|
neverstopbelevin @ Thu Nov 18, 2010 6:26 pm wrote: can someone just write the code
Nope. We don't do your work for you. |
|
|
|
|
|
|
|