Button pressed, then released

Previous topic - Next topic

Jonás Perusquía

Hello my friends, i come here to ask you if there is any way to change the value of a variable but after releasing the pressed button

Code (glbasic) Select
a=0
WHILE TRUE
MOUSESTATE mx,my,b1,b2
IF b1= TRUE THEN a=1
SHOWSCREEN
WEND

using this will change the value at pressing, but how to change value after releasing?


thank you in advance
<HTML><BASIC><EC>
Be free and do good things

Ruidesco

Quick hack:
Code (glbasic) Select
a = 0
last_b1 = FALSE
WHILE TRUE
    MOUSESTATE mx, my, b1, b2
    IF b1 = TRUE THEN a = 1
    IF b1 = FALSE AND last_b1 = TRUE THEN a = "just released!"
    last_b1 = b1
    SHOWSCREEN
WEND

Jonás Perusquía

#2
thank you for your valuable help! , i have written the next based on your code:

Code (glbasic) Select
GLOBAL a,mx,my,b1,b2,last_b1

a = 0

TYPE click
last_b1

FUNCTION call:
self.last_b1 = FALSE
ENDFUNCTION

FUNCTION released:
self.last_b1 = b1
ENDFUNCTION
ENDTYPE

GLOBAL rel AS click

WHILE TRUE
MOUSESTATE mx, my, b1, b2
IF b1 = FALSE AND rel.last_b1 = TRUE THEN a = a+1
rel.released();
PRINT a,200,200,TRUE
SHOWSCREEN
WEND


WORKS TERRIFICALLY WELL :)
<HTML><BASIC><EC>
Be free and do good things

matchy

#3
Here is my updated mouse function:
Code (glbasic) Select

// matchy's mouse lib - Mar/Apr 2013
TYPE _point
x
y
last_x
last_y
ENDTYPE

TYPE _mouse
zorder
id
ver AS _point
b1
b2
last_b1
last_b2
last_x_down
last_y_down
joy_x
joy_y
joy_z
last_joy_x
last_joy_y
last_joy_z
toggle_x
toggle_y
toggle_z
toggle_last_x
toggle_last_y
toggle_last_z
axis_x
axis_y
state_b1
state_b2
state_off = 0
state_down = 1
state_on = 2
state_up = 3
state_move = 4
anim_b1
anim_b2

FUNCTION Update:
// self.id = self_id
SETACTIVEMOUSE self.id
self.ver.last_x = self.ver.x
self.ver.last_y = self.ver.y
self.last_b1 = self.b1
self.last_b2 = self.b2
self.last_joy_x = self.joy_x
self.last_joy_y = self.joy_y
self.last_joy_z = self.joy_z
self.axis_x = 0
self.axis_y = 0
MOUSESTATE self.ver.x, self.ver.y, self.b1, self.b2
SELECT self.b1
CASE 0
SELECT self.last_b1
CASE 0
self.state_b1 = self.state_off
self.anim_b1 = 0
CASE 1
self.state_b1 = self.state_up
self.anim_b1 = 0
ENDSELECT
CASE 1
SELECT self.last_b1
CASE 0
IF self.anim_b1 = 0
self.state_b1 = self.state_down
self.last_x_down = self.ver.x
self.last_y_down = self.ver.y
ELSE
self.anim_b1 = 0
ENDIF
CASE 1
self.state_b1 = self.state_on
INC self.anim_b1
IF self.ver.x <> self.ver.last_x AND self.ver.y <> self.ver.last_y
self.state_b1 = self.state_move
ENDIF
self.axis_x = self.last_x_down - self.ver.x
self.axis_y = self.last_y_down - self.ver.y
ENDSELECT
ENDSELECT
IF self.id = 0
SELECT self.b2
CASE 0
SELECT self.last_b2
CASE 0
self.state_b2 = self.state_off
self.anim_b2 = 0
CASE 1
self.state_b2 = self.state_up
self.anim_b2 = 0
ENDSELECT
CASE 1
SELECT self.last_b2
CASE 0
self.state_b2 = self.state_down
self.anim_b2 = 0
CASE 1
self.state_b2 = self.state_on
INC self.anim_b2
ENDSELECT
ENDSELECT
self.joy_x = GETJOYX(self.id)
self.joy_y = GETJOYY(self.id)
self.joy_z = GETJOYZ(self.id)
ENDIF
ENDFUNCTION
ENDTYPE

GLOBAL mse AS _mouse
GLOBAL ver AS _point

loop()

FUNCTION loop:
SYSTEMPOINTER TRUE
WHILE TRUE
mse.Update()
IF mse.state_b1 = mse.state_move
DRAWLINE 0, 0, mse.ver.x, mse.ver.y, RGB(255 - RND(64), 255 - RND(64), 255 - RND(64))
ENDIF
SHOWSCREEN
WEND
ENDFUNCTION


Jonás Perusquía

thank you matchy for sharing your code with me and with the others, can you explain me how to put it to work? thanks in advance
<HTML><BASIC><EC>
Be free and do good things

Jonás Perusquía

Ruidesco, i had some issues with your code but everything should be working now :)

the reworked code is now like this:
Code (glbasic) Select
GLOBAL a,mx,my,b1,b2
a = 0
TYPE click
last_b1

FUNCTION released:
self.last_b1 = b1
ENDFUNCTION
ENDTYPE

GLOBAL rel AS click

SYSTEMPOINTER TRUE

WHILE TRUE
rel.released();
MOUSESTATE mx, my, b1, b2
IF b1 = FALSE AND rel.last_b1 = TRUE THEN a = a+1
PRINT a,200,200,TRUE
rel.released();
SHOWSCREEN
WEND
<HTML><BASIC><EC>
Be free and do good things

matchy

jonaspm, I've updated the code for cut and paste sample. A mse[] array can also be created for multitouch.  :good:

mentalthink

I do something like this:

Code (glbasic) Select
if b1 and RR=0 then lock_Release=true

if lock_Release
I do want I want to do
endif


If you want unrelease, then you have to search some process when you want desactivate...


RR usually I use a simple CONSTANT   constant RR = false or ' 0 '

MrTAToad

Could try something like the following :

previous mouse info = current mouse info
get current mouse info
if previous mouse button = 1 and current mouse button = 0 then deal with button pressed and then released

Hark0

Hi!

@jonaspm, you can download my "skeleton" project file (in my blog)... you can see how I declare and use buttons made by me... very easy.

;)
http://litiopixel.blogspot.com
litiopixel.blogspot.com - Desarrollo videojuegos Indie · Pixel-Art · Retroinformática · Electrónica Development Indie Videogames · Pixel-Art · Retrocomputing · Electronic

Jonás Perusquía

Thank you all, you too matchy and Hark0 :)
<HTML><BASIC><EC>
Be free and do good things