
-----------------------------------
neverstopbelevin
Thu Nov 18, 2010 5:22 pm

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][/code]

-----------------------------------
TokenHerbz
Thu Nov 18, 2010 5:54 pm

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
Thu Nov 18, 2010 5:55 pm

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
Thu Nov 18, 2010 6:06 pm

RE:click counter- revised
-----------------------------------
try my way first :) and post the code. its good to learn about booleans, this example fits it well.

-----------------------------------
neverstopbelevin
Thu Nov 18, 2010 6:10 pm

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
Thu Nov 18, 2010 6:19 pm

RE:click counter- revised
-----------------------------------
A boolean is a variable that can have two values, either true or false.

You can declare it like

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
Thu Nov 18, 2010 6:21 pm

RE:click counter- revised
-----------------------------------
booleans are either, true or false.

you declare one like :
[code]
var checksomething: boolean := false
[/code]

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
[/code]

-----------------------------------
neverstopbelevin
Thu Nov 18, 2010 6:26 pm

RE:click counter- revised
-----------------------------------
can someone just write the code :P

-----------------------------------
TheGuardian001
Thu Nov 18, 2010 7:48 pm

Re: RE:click counter- revised
-----------------------------------
can someone just write the code :P
Nope. We don't do your work for you.
