My problem is when I press my mouse button over a button I want it to register as it being clicked but just once at the click not the press. So when I Click and hold my mouse button it will only register the button being pressed once and at the start of the click of the mouse button.
I got that to work but what is happening when I dont click on the button and click sumwhere else on the screen then hold the mouse button down and drag the cursor over the button on the screen it will still click the button. I want it to only click if the mouse is already scrolled over it. Here is an example of my code so far.
sync on
sync rate 0
do
BP = Pressed(BP)
if Button(screen width()/2, screen height()/2,"GAME",BP)=1 then BP = 2 : print "hello"
sync
loop
function Button(x1,y1,word$,PB)
Pressed=0
x2=Text Width(word$)
y2=Text Height(word$)
if mousex()>x1 and mousex()<x1+x2 and mousey()>y1 and mousey()<y1+y2 then ScrolledOver=1 else ScrollOver = 0
if ScrolledOver=1 then ink rgb(0,255,0),0 else ink rgb(255,255,255),0
if PB = 1
if mousex()>x1 and mousex()<x1+x2 and mousey()>y1 and mousey()<y1+y2
Pressed=1
endif
if pressed=1
Pressed=Mouseclick()
else
pressed = 0
endif
endif
text x1,y1,word$
endfunction pressed
function Pressed(PB)
tempButton=mouseclick()
if tempButton<>0 and PB = 0 then PB=1
if tempButton=0 then PB=0
endfunction PB
So as you can see if you scroll over the button Game it turns Green then if you click it, hello appears. Now if you click somewhere else on the screen and then drag the mouse over the Game button it will still print hello world. I dont want it to do that I only want it to print Hello if the mouse cursor is already over the button and then pressed.
I tried lots of different ways to get it to work but maybe I am just going about it wrong, Please take a look at my code, any help is greatly appreciated. Thanks!