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 / Tutorial - The Definitive Guide To Making In-Game Menus

Author
Message
jason p sage
16
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 10th Mar 2008 18:05
Bro - Make a new Thread with a DECENT subject line like "Healthbar for my player" or something. Then others who come after you searching for similiar stuff will find your thread

DB newbie
18
Years of Service
User Offline
Joined: 13th Nov 2005
Location: um..... i dont remember.
Posted: 19th Mar 2008 00:33
ok finally TDK i am back. i used your DBA tidy and here is the source code.





Come see the WIP!

TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 19th Mar 2008 01:16
Cool!

Even I can read that now!

Much better don't you think?

TDK_Man

DB newbie
18
Years of Service
User Offline
Joined: 13th Nov 2005
Location: um..... i dont remember.
Posted: 19th Mar 2008 01:26
yes it does look much nicer....you should make a tutorial on how to proparly indent code. it would help alot for people like me


Come see the WIP!

jason p sage
16
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 19th Mar 2008 02:14
May I throw in my Two Cents on Code formatting? I do this EVERYDAY because I'm a professional programmer - but this doesn't mean I'm RIGHT - Let me Start by saying one of my "bosses" thinks my code is easy to read.. yet the first thing he does is (in my mind) slaughter it. But he's not slaughtering it ... He likes tabs, I don't. For him, the TABS make indents easier to see. For Me, I use the cursor scrolling up and down to match nesting.

(See a point here?) The point is the code should be readable, and things like indentation can give you hints to what / why you did something in the past... like when you open a program you wrote a few months ago.

In fact... the ability to read a program a year from now - and get the jist - is a good measure (at least mentally) on how your code should be laid out.

1: It should work for you.
2: You should be able to discern Nesting of loops, if statements, switch or case statement
3: Comments are great
4: Breaking code into "Chunks" separated by whitespace (for some) makes each "group of code" more readable and the togetherness of it all usually speaks to how they are in fact related to eachother

Tabbing? I HATE tabs... Mostly because from one editor to the next, they can vary - (and really Whack your formatting) I like 2 spaces. The boss I mention would do well with 4 I think - mostly because I don't think he cares to adjust tabs to spaces in the editor settings... The reason I choose only 2 spaces is because in complex programs, and deeply nested bit of code, its easy to navigate I think using the cursor... by using up/down arrow. Another benefit of using spaces consistantly is most editors don't toss the cursor left or right when you're trying to line up nests tracking down a missing "END IF" or "NEXT" or some other nest construct terminator!

Here is a clip of some meaningless code... but note... regardless of WHAT it does... it makes SOME sense:


DB newbie
18
Years of Service
User Offline
Joined: 13th Nov 2005
Location: um..... i dont remember.
Posted: 23rd Mar 2008 04:54 Edited at: 23rd Mar 2008 04:55
so... uh TDK about my problem with goign back to the menu?

can you help?

P.S i finally found out were your name "TDK" is from. my dad brought home a disk and i saw it and i was like Holy crap TDK really is something.


Come see the WIP!

TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 23rd Mar 2008 05:35
Sorry - didn't realise you`d pasted that code with a problem.

The plain and simple answer is that you need to read up on how Procedures and Functions work.

You are calling procedure A then calling function B from procedure A - which is OK.

However, you are then then calling procedure A again from function B before it has been able to return naturally. You simply can't do this!

Well, obviously you can - as your snippet shows - but it's totally wrong and an excellent way to eventually screw ALL your programs up if you continue the practice!

These are the basics of programming and if you don't understand this sort of thing, it doesn't matter how good you are at other more advanced things, you programs will simply not work. Period.

I've mentioned tutorials before to you a while back, but I'll say it again. Please read beginners tutorials 1 to 4 from my tutorials page.

Yes, I know they will be a bit boring as you've now done a bit of programming on your own, but the sort of things you don't understand at the moment are covered in them.

As you are writing programs like the code snippet you posted above, it's clear that you either didn't read them last time - or you didn't read them carefully enough to understand them.

On the other side of the coin, it may be that you did read them but I've not made them clear enough. If this is the case please let me know and I'll fix the problem. Just let me know what parts were unclear...

Having said all that, the section called 'Adding Menus To Your Programs' at the end of the menus tutorial tells you exactly what you are asking. It covers adding both single and multiple menus to your programs.

But, you need to get to grips with calling procedures and functions first or you are going to have exactly the same problem with all of your programs.

TDK_Man

Frankie Pawnage5
15
Years of Service
User Offline
Joined: 14th May 2008
Location: squidwards nose
Posted: 17th May 2008 07:26
hey i might've missed this in the tut but is there a way to make a menu IN the game??...like for example, if you wanted to make an FPS and you wanted lets say like a traveling weapons merchant, is there a way you can tap a button and a buying menu will come up?

FrAnKiE
aarrowh
16
Years of Service
User Offline
Joined: 19th Oct 2007
Location:
Posted: 14th Jul 2008 04:45
I'm trying to use the invisible image menu style to make my games menu, but nothing is working, I get the image up fine, but nothing else works, the color value thing in the upper right corner does not work as well. Any light on the subject would be great.

Thanks in advance,

aarrowh

SOMEDAY, I will have coding skillz... :p
Sinani201
17
Years of Service
User Offline
Joined: 16th Apr 2007
Location: Aperture Science Enrichment Center
Posted: 15th Jul 2008 03:30
You have to replace the confusing color values with the colors that you did.


aarrowh
16
Years of Service
User Offline
Joined: 19th Oct 2007
Location:
Posted: 15th Jul 2008 20:29
Ok, and how do I get the color values...haha..I know the RBG numbers but not the color values.

SOMEDAY, I will have coding skillz... :p
Sinani201
17
Years of Service
User Offline
Joined: 16th Apr 2007
Location: Aperture Science Enrichment Center
Posted: 16th Jul 2008 03:12 Edited at: 16th Jul 2008 03:15
You don't have to use the color values, just use the RGB color value and it will work find.

For instance,instead of case 67487 (wierd number) put in case rgb(100,200,150)


BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 16th Jul 2008 12:10
The point of the color values is to increase system performance. Basically, every time you use rgb, the computer has to calculate the color number (the weird one). Every time you simply put in the number, it doesn't have to take the time or resources to do that calculation, allowing more resources to be used for the actual game/program.

Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?
aarrowh
16
Years of Service
User Offline
Joined: 19th Oct 2007
Location:
Posted: 17th Jul 2008 06:32 Edited at: 17th Jul 2008 06:36
oh, ok thanks, I will try it out

*edit*

I changed it but I get an error when trying to compile saying "Could not determine Paremeter type of 'RBG(250,000,000)'"

SOMEDAY, I will have coding skillz... :p
Ferke
15
Years of Service
User Offline
Joined: 17th Jul 2008
Location:
Posted: 17th Jul 2008 12:18
Thank man, it helped a lot!

Ferke
aarrowh
16
Years of Service
User Offline
Joined: 19th Oct 2007
Location:
Posted: 22nd Jul 2008 20:51
since nobody saw my post above I shall repost and hopefully get some help

I changed it but I get an error when trying to compile saying "Could not determine Paremeter type of 'RBG(250,000,000)'"

SOMEDAY, I will have coding skillz... :p
RedFlames
16
Years of Service
User Offline
Joined: 25th Aug 2007
Location: Germania
Posted: 22nd Jul 2008 22:08
is that RBG highlighted?! if it isnt you should've noticed that its wrong, as its RGB instead... The order is always Red,Green,Blue.

aarrowh
16
Years of Service
User Offline
Joined: 19th Oct 2007
Location:
Posted: 23rd Jul 2008 07:16 Edited at: 23rd Jul 2008 19:49
*edit* oh, I get it, no it will not highlight but I've put in the RBG and everything in correctly as far as I know.

the codez



SOMEDAY, I will have coding skillz... :p
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 24th Jul 2008 16:36
Like RedFlames says, RBG is wrong!

It should be:

Case RGB(250,0,0)

If you type Print RGB(250,0,0) on the command line, DB will print the actual colour value. Simply use that value instead of the RGB() function:

Case 16384000

TDK_Man

aarrowh
16
Years of Service
User Offline
Joined: 19th Oct 2007
Location:
Posted: 24th Jul 2008 19:56 Edited at: 24th Jul 2008 20:19
*edit*

Ok, now that the program boots up, the menu still isn't working. It is not registering that I'm clicking inside the colored zone making the if statement return a 0. I have no idea what I'm doing wrong.

Here's some code.



SOMEDAY, I will have coding skillz... :p
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 24th Jul 2008 20:34


Where is the CheckRegion() function in your code?

You also only need one Sync in the main loop.

TDK_Man

aarrowh
16
Years of Service
User Offline
Joined: 19th Oct 2007
Location:
Posted: 25th Jul 2008 04:05
Oh, Sorry, forgot to put that in there, I seperate functions from the main loop...my bad.



There it is.

SOMEDAY, I will have coding skillz... :p
neilo20
15
Years of Service
User Offline
Joined: 25th Jul 2008
Location: UK
Posted: 26th Jul 2008 01:05
Hi ya thought im very new to this and I have been searching the forums when I came upon this. This was exactly what I was looking for. So I've saved off the images for the sprite method and pasted the code from the tutorial. But it doesnt work properly. The buttons appear and function as expexted but the background is blue?
Any ideas anyone

heres my code altho should be same as tutorial apart from the file paths
aarrowh
16
Years of Service
User Offline
Joined: 19th Oct 2007
Location:
Posted: 27th Jul 2008 05:34
If I'm correct, "If OverButton <> 0 Then Gosub HandleButton"

is missing part of the IF statement. I think its like this




If thats wrong, sorry.

SOMEDAY, I will have coding skillz... :p
neilo20
15
Years of Service
User Offline
Joined: 25th Jul 2008
Location: UK
Posted: 27th Jul 2008 14:07
thanks for trying but unfortunately that didnt help
neilo20
15
Years of Service
User Offline
Joined: 25th Jul 2008
Location: UK
Posted: 27th Jul 2008 14:19
I thoguth I would strip the code down to the most basic possible, place the background and 1 button down with no extra code. Even with that it still shows the button fine but has a blue background

here is my stripped down new code


the graphics I have just right-clicked and saved off the tutorial above.
aarrowh
16
Years of Service
User Offline
Joined: 19th Oct 2007
Location:
Posted: 14th Sep 2008 04:46
Well I'm back with another menu question. I'm trying to get your pixel collision method to work. but I keep getting "Image number illegal at line 98"

Here's the code. (line 98 will have on both sides)



Thanks in advance

Aarrowh

SOMEDAY, I will have coding skillz... :p
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 15th Sep 2008 01:50
Inc SprNum in your nested loop is executed six times:

Ny=0: Nx=0 >> SprNum = 1
Ny=0: Nx=1 >> SprNum = 2
Ny=1: Nx=0 >> SprNum = 3
Ny=1: Nx=1 >> SprNum = 4
Ny=2: Nx=0 >> SprNum = 5
Ny=2: Nx=1 >> SprNum = 6

As the button images loaded only go up to number 3, trying to use image 4 results in an illegal image error.

My guess is that you need to move the Inc SprNum line to between the Next Nx and the Next Ny lines.

TDK_Man

aarrowh
16
Years of Service
User Offline
Joined: 19th Oct 2007
Location:
Posted: 15th Sep 2008 18:38 Edited at: 15th Sep 2008 18:42
Well, it opens now. But the background image is blue and missing, and its not detecting sprite collision.

Thnx for the help so far

SOMEDAY, I will have coding skillz... :p

Login to post a reply

Server time is: 2024-05-02 12:08:19
Your offset time is: 2024-05-02 12:08:19