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 / Problems with Functions. Or loops. I'm not sure. Making menu's.

Author
Message
Dante Corwyn
21
Years of Service
User Offline
Joined: 18th Mar 2003
Location:
Posted: 10th Jul 2006 22:02
I'm using DarkBasicClasic. What's going on is after I press either 1,2 or 3, DB crashes out. And I get one of those 'DB had to close, send report to Microsoft things'. No idea why. Here's my code here.



The other annoying thing is if I try to make the menu a function with Function MainMenu() , then I just get dumped back to DarkEdit with "Runtime Error at Line 17(the line I start the function). Program ran into a function declaration at line 17". Which was kinda the point. Any idea's? Thanks.
Crit
18
Years of Service
User Offline
Joined: 24th May 2006
Location:
Posted: 10th Jul 2006 22:32 Edited at: 10th Jul 2006 22:33
That nested "if" structure is probably your problem. I know Dark Basic Pro wouldn't let you do that. This may seem like bad programming, but you could get rid of that structure and just make it regular if statments. This isn't in a place that would benefit from optimized code.



And make sure your Function Mainmenu() is declared after the "end"

CHESS ENCOUNTER
Demo
WIP
Dante Corwyn
21
Years of Service
User Offline
Joined: 18th Mar 2003
Location:
Posted: 10th Jul 2006 23:23
That works. Cheers for the quick responce. One thing that seems a little odd to me though is how functions seem to work, at least in DBC. I ended up having the main menu in the main body, and near-enough duplicating it in a function (it just comes up as another "Runtime Error at Line blah,Program ran into a function declaration at line blah". Thought it was a little badly structured, or is this how DBC sets itself up? Probably better if I show you the code again.



It hops back and forth from the Instructions function fine, but it seems odd that I cannot set a function right at the start; that I have to duplicate it as a function without having it as a function in the first place. Is this normal, or is this to encourage me to get BB Pro?
Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 11th Jul 2006 14:53 Edited at: 11th Jul 2006 14:56
No, just looks like you are misunderstanding (a little!) the best way to use functions! Functions are used to remove duplicate code! So write a function that takes your title and choices and makes a menu then waits for an input. e.g.
Function DoMenu(Title$,menu1$,menu2$,menu3$)

Blah...

endfunction Menu

Then have your main code feed the function the right menu title and choices at the right time, and then deal with the returned input.

And functions have to be defined right at the end, otherwise the compiler would just carry on into your function when it shouldn't!

"You get what everyone gets, you get a lifetime!" - Death, The Sandman Library

First you Dream, then you ... - Neil Gaiman, 2001

Login to post a reply

Server time is: 2024-09-25 03:31:35
Your offset time is: 2024-09-25 03:31:35