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 / Function - Button

Author
Message
Kivu_Rako
20
Years of Service
User Offline
Joined: 10th May 2004
Location:
Posted: 13th May 2004 03:49
okay...
i know several ways to do this, but i want to do it the easiest way.
i want to create buttons, but make a function to do it, i.e. so i dont have to type alot every time i want a button.
this is what i have...

function Button(left,top,right,bottom,branch)
box left,top,right,bottom
if mouseclick()=1
x=mousex()
y=mousey()
if mousey()>top
if mousey()<bottom
if mousex()>left
if mousex()<right
goto branch
endif
endif
endif
endif
endif
endfunction
but since the goto branch is there, it wants to actually goto the branch, rather than make it part of the function.
is there anyway to get around this or will i have to do the:

function button(left,top,right,bottom)
if mousex()<right and mousex()>left and mousey()<bottom and mousey()>top
endfunction

then put the goto after it?
if so please tell me, or tell me what to do to fix it.

btw, i am well aware i could use "and" in my original program to shorten in, but i havent done that yet.

"geez, its probably a noobish mistake too!"
MikeS
Retired Moderator
21
Years of Service
User Offline
Joined: 2nd Dec 2002
Location: United States
Posted: 13th May 2004 06:12
Hmm, I tried to get a goto in there but I failed. the str$() command didn't help me too much. Not sure if it's worthwhile to use a goto statement in a function. You'll probebly be better off just adding a few lines of code like.

If mousex()>10 and mousey()>0 then goto location.

Then you can just use your nifty function to create the buttons and easily code the goto.

Anyways, not sure if that's what you wanted to here but I made a button function for you.





A book? I hate book. Book is stupid.
(Formerly known as Yellow)
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 13th May 2004 07:33 Edited at: 13th May 2004 08:11
kivu_rako,

If you are looking to create an app and can use MS Windows buttons Rob k's blueIDE has the functionality built in. Here's the link.

http://blue.robert-knight.net/

Also pretty sure IanM or TCA has a plugin.

Since you may want to code this yourself and/or use personally designed buttons. I'll try to look at the code when I get a chance.

From a quik read-over. You may want to use a 'select case statement'. Though using the second method you posted is how I have done it (using a combination of AND/ORs. I've never worried about optimizing it. I'll look at it in the morning and check the codebase.

The only thing about your code that is confusing me is why you want a goto branch. More than likely you would be calling this function from inside the main loop and returning a (IsClicked) value, either True or False.

Wait... I think that I see you are using the same function to create the button. I don't think you want to do this. I would create a user defined type 'ButtonRect' that contains 4 ints for the x&y corners & a couple of other paramaters usually Bools like (IsClicked, IsActive, ButtomIdNum, text$, etc...). Then in the game-loop use I make a call to something similar to your fucntion. I prefer to have buttons have an awareness. In other words I write the code from the perspective of the buttons asking, "am I being clicked"; rather than the mouse pointer asking "am I clicking a button".

I know this all sounds confusing. I'll post some code tomorrow.

Login to post a reply

Server time is: 2024-09-22 09:51:32
Your offset time is: 2024-09-22 09:51:32