Button on\off(modifing a button...)

Blitz3D Forums/Blitz3D Beginners Area/Button on\off(modifing a button...)

Valgar(Posted 2003) [#1]
I'm trying to write a code to change the image of a button....
I want something that if i hit that button it's change it's graphics.....and when i hit that another time it's return to his original image and so on,to simulate a simple "button on","button off" that change if i give him thw input to.
Here's a part of the wrong code:

if mousedown(1) and mx>711 and mx<790 and my>0 and my<17
setscroll=setscroll_on ;swap of the image if i held down the mouse button
endif


GfK(Posted 2003) [#2]
Const SetScroll_On = 1
Const SetScroll_Off = 0

If MouseDown(1)
  If MX>711 and MX<790 and MY>0 and MY<17
    If SetScroll = SetScroll_On
      SetScroll = SetScroll_Off
    Else
      SetScroll = SetScroll_On
    Endif
  Endif
  While MouseDown(1)
  Wend
Endif



Valgar(Posted 2003) [#3]
Urgh i didn't think that's so easy the resolution...
I have tried all but not the most obvious thing -_-'
Many thanks!


GfK(Posted 2003) [#4]
If SetScroll can only be either True or False (1 or 0), you can simplify the code a little:
If MouseDown(1)
  If MX>711 and MX<790 and MY>0 and MY<17
    SetScroll = 1 - SetScroll ; This will toggle SetScroll between 0 and 1
  Endif
  While MouseDown(1)
  Wend
Endif



Drago(Posted 2003) [#5]
or you could go
setscroll = not setscroll

which also toggles its value from 0 to 1 etc.


_PJ_(Posted 2003) [#6]
With the original code, though - more than the two states are possible. Allowing for a choice of any number of settings for the button:

ie. Setscroll 0 ......... OFF
Setscroll 1 ......... ON
Setscroll 2 ......... AUTO
Setscroll 3 ......... ADVANCED

(or whatever, depending on button uses)