Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / on off button

Author
Message
HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 14th Apr 2005 06:16
Hi All

Please how do I make this bit of code go click once for on then click again of off.

if mousex()>0 and mousex()<14 and mousey()>0 and mousey()<20
if mouseclick()=1
click=1
else
if mouseclick()=1 and click=1
click=0
endif
endif
endif

In Space No One can Hear You Scream! (When your comm Line is cut?)
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 14th Apr 2005 06:39


heres an example, all you do is subtract the last value you had from 1, so

click=0----1-0=1---click=1
click=1----1-1=0---click=0
click=0----1-0=1---clcik=1
etc

thats the simple way to do it anyway, the repeat until line makes sure you have released the button before the code continues (busy waiting), if you want to make sure you don`t get busy waiting then set a variable to the current timer +250...eg

clock=timer()+250

so remove the lines

repeat
until mouseclick()=0

and replace them with

clock=timer()+250

and alter the calling line to read

if mouseclick() and (timer()>clock)

so the line can only execute every 0.25 seconds.

Mentor.

PC1:XP, P4 3ghz, 1gig mem, 3x160gig hd`s, Radeon 9800pro, 6 way sound.
PC2: Linux, AMD 2ghz, 512mb ram, Nvidia GeForce4mx, 16 bit SB.
PC3: XP, laptop, intel 2.6ghz celeron, ATI 9000igp, 256mb
HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 14th Apr 2005 06:55
Cheers Mentor works a treat, I see how works but I am still ,

In Space No One can Hear You Scream! (When your comm Line is cut?)
wmf
19
Years of Service
User Offline
Joined: 6th Nov 2004
Location:
Posted: 14th Apr 2005 09:31
here is another way
Mr Bigger
19
Years of Service
User Offline
Joined: 31st Jan 2005
Location: was here!
Posted: 14th Apr 2005 11:08
This code will do it in one line.
HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 15th Apr 2005 03:05
Cheers Now there something to chew on.

Now I got it going, how do you make click work on two or more places, say top left and top right, can I use the same click or do I have to make a click2.

(making drop down menus system)

Trying to get a radio button system if I click button 1 it turns on then if I click buton 2,3 or 4 it will turn off button 1 and turn on button I have clicked.

In Space No One can Hear You Scream! (When your comm Line is cut?)
wmf
19
Years of Service
User Offline
Joined: 6th Nov 2004
Location:
Posted: 15th Apr 2005 12:10
try something like this. buttons are for testing only.
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 15th Apr 2005 12:50
the best way that I have found to check for mouse collision with buttons is to put a sprite(completely black so that it will be transparant) at mousex(),mousey()
something like this


it isn't perfect but it does work
HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 15th Apr 2005 22:45
Cheers for the diffrent ways to detected sprites but I am not using them yet, as this drawing boxes on the screen and using the mouse box checking system.

I am making drop down menu system, so what I had in the post above works ok if I only have one to check, however I have upto 8 I wish to check, this means that if I click menu 1 it drops down with its choices then if I click on menu 5 , menu 1 will close up and menu 5 open.

ok here's the code so far


In Space No One can Hear You Scream! (When your comm Line is cut?)
Underworld 1020
20
Years of Service
User Offline
Joined: 2nd Mar 2004
Location: NY, USA
Posted: 16th Apr 2005 00:34 Edited at: 16th Apr 2005 01:03
Well, I haven't made a drop down system yet, but I have made something for Radio buttons.

Here It Is:


Eventually I want the user to be able to specify how many sets, buttons, color of the buttons, size of the buttons. Right now it will create three Radio buttons and checks for collision with them and if you click on one, then the others turn off.

HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 16th Apr 2005 00:57
Cheers like the way you get the x1,y1,y1,y2 data to the Circle command.

PS Anyone else down loading this remove the dot in this line

For Radius= 1 To 2 : Circle RadioSet(Set,Num,1),RadioSet(Set,Num,1,1),Radius : Next Radius

it trys doing it but .1 to 2 takes it a very long time.

In Space No One can Hear You Scream! (When your comm Line is cut?)
Underworld 1020
20
Years of Service
User Offline
Joined: 2nd Mar 2004
Location: NY, USA
Posted: 16th Apr 2005 01:06
I think there is something on drop down windows style menus somewhere on this site, I'll try looking for it.

EDIT: I fixed the .1 thing.

HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 17th Apr 2005 22:55
How did you fix your post?

In Space No One can Hear You Scream! (When your comm Line is cut?)
NanoBrain
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 18th Apr 2005 09:18 Edited at: 18th Apr 2005 09:19
HowDo,

When I first began programming in this language, the on/off button was quite tricky to me. Try this code snippet below.



Two variables are needed to make this program work properly. First, there is click, and then there is control. click is the boolean variable to change the color of the box. That if it is a value of 1, it is on, else it is off. control does just what it is named as. I could have placed the code like this:



However, the box would have never changed colors this way, because click would have always ended up being the value of 1. So, I had to throw a control variable in. This variable let's each if statement know if the box has been clicked on within that same program loop.

Now, somehow I have to reset control back to te value of 0 given certain circumstances. Or else, the button would only have the chance to change it's color once. So, I have placed that if the mouse is not pressed or the cursor is not over the box, control is then set to 0.

+NanoBrain+

Login to post a reply

Server time is: 2024-09-23 17:22:49
Your offset time is: 2024-09-23 17:22:49