How long mouse is pressed down on a certain buton!

Started by Joseph, Sat 02/10/2010 18:22:57

Previous topic - Next topic

Joseph


Allo mes amis/hola me amigos/yo homeys!!

Yo! I want know how i can do this without losing my muind!!!!!!!!!!11!!

When my mouse is over a certain button aand is pressed down, i want to have a textbox show us all how long the mouse is over it and pressed down on that button with numbers going up and up and up, starting at ZERO. when the mouse is finally let go, woops!! the text is reset back tio nothing a.ka --> ZERO! tajht way when i reclick and hold down on that button, the counting starts all over again from ZERO.this will show us all how long a player holds down the mouse  on that certain button! YESSSSSSSS

i tried and tried and cried and cried: me is super dumbo  := :o

???

thats twhy ui come here to ask :)
Spread the love...One.Turtle.At.A.Time.
http://www.youtube.com/watch?v=y0A77rohcyg

Knox

Hey Joseph!

This is the first time I actually feel I can answer a question, unless someone has a better solution :P
Code: ags

int iLMclick; //put that at the top of your global script

//Put this in your rep_exec:
        overGuiControl = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
        if (mouse.IsButtonDown(eMouseLeft) && overGuiControl == yourButtonName)
        {
          while (mouse.IsButtonDown(eMouseLeft))
          {     
            textboxName.Text = String.Format("%d", iLMclick);
            Wait(1);
            iLMclick = (iLMclick + 1);
           }
          lblHotspot.Text = "0";
          iLMclick = 0;
        }


I tested in my game and it works!
--All that is necessary for evil to triumph is for good men to do nothing.

tzachs

While general_knox method will work as expected, it can be problematic since it will prevent other stuff from happening while the mouse button is pressed (animations etc).
In order to solve that, we need to remove the "while" from the repeatedly_execute, so that only one check will run for each game loop.

Something like this (didn't test it, though):
Code: ags

int iLMclick; //put that at the top of your global script

        //Put this in your rep_exec:
         overGuiControl = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
         if (mouse.IsButtonDown(eMouseLeft) && overGuiControl == yourButtonName)
         {              
            iLMclick++;
         }
         else
         {
            iLMclick = 0;
         }
         textboxName.Text = String.Format("%d", iLMclick);
                       


SMF spam blocked by CleanTalk