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 / Help with my command prompt style thing?

Author
Message
hotron
19
Years of Service
User Offline
Joined: 1st Oct 2005
Location: Australia
Posted: 16th Mar 2008 07:10 Edited at: 16th Mar 2008 11:33
Ok, I'm making a command prompt style program and it doesn't seem to work properly. You have to enter the commands in several times for them to work .

Things I need help with:

Fixing it so you only need to enter the commands once.
Scrollbar. (Working on)



This is the complete source code so far:
(Very very early in prototype stage)




Thanks in advance
Hotron
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 16th Mar 2008 08:14 Edited at: 16th Mar 2008 08:35
ok, I would suggest a few things

1. Indent your loops
2. Don't make your subroutines the same as REAL commands (make them do_command or something like that)
3. Take out the return after hotool and make all of the "gosub hotool" lines "goto hotool"
4. Even though your end command is in a subroutine, put another in. This should separate your subroutines from your main code, this stops the program from accidentally running into subroutines and executing them when they aren't supposed to

*NOTE: You may want to consider using functions rather than subroutines for your different commands.


ok now for your if commands
what the first one in every set says basically if the input is THIS then do that but if it isn't THIS then go back.

this begins to contradict itself with other if's structured the same way (it will always go back to hotool if it isn't the first one)
try using the select command. This is like a multi-if then statement. Not sure of the syntax I think it is:

the variable in this case would be the input string
the value1,2,and 3, would be the different commands "print" "exit" etc. the command section is where you put all the things that should be done if the variable equals the value.

now to answer your question of why you had to type the same thing multiple times, I will follow your programs logic starting from hotool and assuming that the command is cls.


As you can see, because of the use of gosubs, rather than goto, you are constantly jumping back and forth.

You could even probably put the input command into your do loop and omit the gosub/goto hotool altogether, then at the end of your command subroutines just return.

Hope these tips help!

Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?
hotron
19
Years of Service
User Offline
Joined: 1st Oct 2005
Location: Australia
Posted: 16th Mar 2008 09:16 Edited at: 16th Mar 2008 09:25
Most of the stuff you said I don't understand. The stuff that I could understand made it worse.
(none of the commands work AT ALL now)

but thanks anyway
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 16th Mar 2008 10:34 Edited at: 16th Mar 2008 12:41
Quote: "make all of the "gosub hotool" lines "goto hotool""


Bad advice - the only bit though, as the rest is good. You should never suggest that a newcomer to programming use Goto rather than Gosub.

@hotron

You're on the right track, but not quite there yet. You just need to get used to how subroutines work. There's a tutorial which covers the subject here:

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

Tutorial 2 is the one you want, but numbers 1 to 4 you might find very useful also.

BN2 Productions is correct about indenting. Learn about it earlier rather than later. It's important as it makes your programs easier to read and follow - especially if you post them on here and expect others to help you solve problems.

I won't look at an unindented code snippet more than a few lines long and I know others won't either so if you don't indent, you could be losing out on help from a lot of other users.

Here's your program a little closer to what it should look like.



There are lots of other things wrong with the program - like the ',1' in the ink command, but that's only because as a beginner you don't yet fully know how the commands work. The above tutorials will help you with that and you can then build on your program...

Quote: "Fixing it so you only need to enter the commands once."


How I changed it should work, but don't forget that how you've written it, it's case sensitive. Look up the Upper$() command in the Help (F1).

Quote: "Scrollbar. (not necessary but I would like lots)."


Look on the code snippets board. I wrote a scrolling text box snippet which is on there.

TDK_Man

hotron
19
Years of Service
User Offline
Joined: 1st Oct 2005
Location: Australia
Posted: 16th Mar 2008 11:32
Thank you TDK! You are my hero.
Hmm so thats what the indentation is supposed to look like. Never enough thanks

Hotron
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 16th Mar 2008 18:59 Edited at: 16th Mar 2008 19:00
Quote: "Most of the stuff you said I don't understand. "


wrote a quick demo program of the select command, it should keep your if-thens a little neater



and here is how your main loop would look with this


Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?
hotron
19
Years of Service
User Offline
Joined: 1st Oct 2005
Location: Australia
Posted: 18th Mar 2008 04:35 Edited at: 18th Mar 2008 04:37
Ok I have a new problem, I tried putting in an Errorsub (which worked) but i also tried putting in a "Execute file" I exited( after "unrecognized parameter" messages) without saving. But what I was trying to do was execute a file from "EF$" In the Current directory (Whichever the user has chosen). here is what i tried:



* What do i do for command line? I tried putting in "none" and completely removing it and I still got the error messages

And the help files didn't explain anything useful or even helpful. Can Some one please help or explain?

Thanks in advance
Hotron

**EF$ is an input for the execute File command
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 18th Mar 2008 07:28 Edited at: 19th Mar 2008 00:15
The Filename, Commandline and Directory parameters in Execute File are all strings, and no string at all is a NULL string ("").



Keep If..Else..Endif lines separated in DBC as per the help files. You can have problems doing it like that as there's no Endif.

TDK_Man

hotron
19
Years of Service
User Offline
Joined: 1st Oct 2005
Location: Australia
Posted: 18th Mar 2008 22:19 Edited at: 18th Mar 2008 22:47
Edit: Never mind. I fixed it.

Hotron

Login to post a reply

Server time is: 2025-06-04 03:14:32
Your offset time is: 2025-06-04 03:14:32