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.

DarkBASIC Discussion / How Do You Make Buttons?

Author
Message
Irojo
17
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 22nd May 2008 01:46 Edited at: 23rd May 2008 05:27
Hello guys, I have a quick question for you: How do you make simple buttons? Here's a little example of how I do it:




I'd like to know at this point of time, is there anything wrong with doing it this way? Because it seems a heck of a lot faster then making a 'sensitive' area...

TDK Man Scares me.
Not_Maindric
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Omaha, NE
Posted: 22nd May 2008 03:12
I believe that RGB can only use numbers in the 255 range, not 500.. Vorrect me if I am wrong.

Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 22nd May 2008 04:05 Edited at: 22nd May 2008 04:32
@Maindric
255 is the max for colours but higher numbers don't produce an error; they simply wrap and start at 0 again

@Irojo
I don't understand how your code creates a button; buttons have two defining assets, an area in which they exist and presses are detected, and a state (on/off).
your button lacks a state, you need to make sure the button passes a variable containing its state so that this can be used to control the program
your button also lacks a detection area.
Detection is the only real challenge with buttons, here is a simple area detection example: when the cursor is on the left side of the screen the left is highlighted, when on the right the right is highlighted.


Here are a few challenges to test your skills:
1. Change the detection to top and bottom halves of the screen.

It is far better to complete a 10 line program than to start a 10,000 line program.
Irojo
17
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 22nd May 2008 04:35
Thank you very much Obese!

Syntax Error: Bob does not exist
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 22nd May 2008 04:39
[sorry forced to double post]

2. change detection to the four corners of the screen.

3. Detect a box in the centre of the screen.

4. Set up multiple boxes at different positions that change colour when rolled over and clicked.

Some knowledge of arrays would be very useful for these challenges.
Post back with your programs.

cheers

It is far better to complete a 10 line program than to start a 10,000 line program.
Irojo
17
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 22nd May 2008 04:44
Here's it now for the top half of the screen Obese Thanks for your help.

/
sync on
blue= 255

Do
if mousey() <=240 then half= 0 else half= 1
for n= 0 to 1
if n =half then ink blue,0 else ink 0,0
box n*230,n*240,n+639,n+237
next n

sync
Loop

Syntax Error: Bob does not exist
Irojo
17
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 22nd May 2008 04:44
By the way, How do I make code snippets?

Syntax Error: Bob does not exist
Irojo
17
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 22nd May 2008 04:48
Sorry For The Double Posting... (I can't edit yet unless I wait for it to go through :\\ ) When You say "Detect A Box In the Middle Of The Screen" Are you saying it's not visible until the mouse moves over it?

Syntax Error: Bob does not exist
Irojo
17
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 22nd May 2008 05:38
Alright Obese... I got tired and stopped doing the bottom right corner...






I getting tired of this box stuff O_o So instead of doing the code, I'm going to tell you how to do it:


Challenge 1: I already gave you the answer
Challenge 2: The Snippet is above.
Challenge 3: To Detect a Box in the center of the screen, All i have to do is use and's For Example




Challenge 4: First I put in the boxes, then I set it so that when The Mouse moves over it, the color changes:



I think that should do it. Thanks for the challenges Obese. They really made me look hard at the code to study it. I appreciate your time and help.


-Irojo

Syntax Error: Bob does not exist
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 22nd May 2008 06:55
Double posting is not allowed - even with an apology!

In any case, that's not double posting - it's quadruple posting!!

Please wait until your posts are approved - it won't be long before you are off post approval at the rate you are going... assuming you don't get slapped for more double-posting that is!

Buttons:

http://forum.thegamecreators.com/?m=forum_view&t=99497&b=10

Tutorial 16.

Irojo
17
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 23rd May 2008 15:40
Obese, Is there anything wrong with using point() to make a button? Because It seems much easier to me...
Menu Made Using Point()


TDK Man Scares me.
NanoGamez guy
18
Years of Service
User Offline
Joined: 13th Jan 2007
Location: Closer than you think...
Posted: 23rd May 2008 18:36 Edited at: 23rd May 2008 18:37
DON'T use point for that because:
1. It will be way too slow
2. You won't be able to have any buttons the same colour.
3. You won't be able to have anything else on the screen with the same colour as one of the buttons

Also, in you code, don't use functions to display things e.g.:


Use subroutines instead, e.g.:



What are the chemical formulae of:
Sodium Nitrate, Gallium, Manganese and Einsteinium
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 23rd May 2008 19:37
Quote: "It will be way too slow"


How fast does it need to be when clicking on a button?

I use it in one of the tutorial examples - when using hidden button zones. That method allows for multiple buttons of the same colour.

TDK_Man

Irojo
17
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 23rd May 2008 20:30
But functions look pretty.... lol

TDK Man Scares me.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 23rd May 2008 20:38
TDK's method is the only way you could use point effectively and without limiting your graphics, it would look horrible to have every button a different colour

defining a detection area is more work to begin with but after you have the code it's easy to add more buttons wherever you like

It is far better to complete a 10 line program than to start a 10,000 line program.
Irojo
17
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 23rd May 2008 21:05 Edited at: 24th May 2008 00:10
Nvm

It's far better to write a funny signature then to write one of lines.
Irojo
17
Years of Service
User Offline
Joined: 21st May 2008
Location: Eating toast.
Posted: 23rd May 2008 21:07 Edited at: 24th May 2008 04:56
[edited to avoid double posting]

Ok, thanks TDK.

It's far better to write a funny signature then to write one of lines.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 24th May 2008 02:22
Quote: "Are Functions Slower"


There's no noticeable difference between the speed of a function and a procedure if that's what you mean.

For a button clicking routine which is time insensitive, even using the Point command is not a concern.

The Point command is admittedly slow, but unless you were using it hundreds or more times a second then it wouldn't affect your program's speed.

TDK_Man

Login to post a reply

Server time is: 2025-06-06 16:05:40
Your offset time is: 2025-06-06 16:05:40