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 / Little game... need suggstions

Author
Message
1337 programm3r
18
Years of Service
User Offline
Joined: 19th Nov 2007
Location: Your MOM
Posted: 25th Jan 2008 01:15
Im very new to programming, if you were here, I had problems kinda, with using 2d sprites a way long time ago and had to pay attention to school cause my grades were falling, but im back and my goal right now is to enter the 2008 text game contest(not yet anounced but is still comin). I know I have to start slow, but I still want to learn really quick. I have below a little game I just wrote, I was wondering if anyone could give me suggestions on what I could do better, or anything that I could add onto the game.



Also I read the tutorials on data commands and stuff but I dont really know how to use it since I havnt tried, anybody have a suggestion for a proggram that I would need to store data and such for? After reading some posts on text games, I found this to be an important command and Im probably going to need it to make any sort of decent game that wont completely fail the competition.

Super Cool
TDK
Retired Moderator
23
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 25th Jan 2008 01:43
A few suggestions to help you:

1. Learn how to indent code early on. It improves readability and helps you find many errors - especially nesting errors. This is how your function should look:



Notice how you can clearly see where all the programming blocks and loops start and end compared to your version.

2. You have a recursive function there which isn't ideal for the particular program you are writing - even more so if there's no way out of it. For now, you would be better with a main Do..Loop and just Gosub procedures.

3. # does not mean number. It means 'make the variable a float'.

You neither use or need floats (the user can't enter 2.36 as a guess right?), so the float variables simply slow your program down, though this is of more importance in much bigger programs.

There's little you can do to improve this sort of basic program other than to ask the user's name and use it in on-screen messages or improve it visually.

TDK_Man

1337 programm3r
18
Years of Service
User Offline
Joined: 19th Nov 2007
Location: Your MOM
Posted: 25th Jan 2008 01:57
Thank you TDK. I dont really know what I was thinking with the number sign lol I think it might have come from my bit of expirience with visual basic, its wierd not having to declare variales

Super Cool
Sinani201
19
Years of Service
User Offline
Joined: 16th Apr 2007
Location: Aperture Science Enrichment Center
Posted: 25th Jan 2008 05:54
TDK created a program that automatically indents your code.

Seriously, how do you make the little blue text come up below your message?
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 25th Jan 2008 19:34 Edited at: 25th Jan 2008 19:36
Quote: "TDK created a program that automatically indents your code."

I don't like that program but if you really can't indent then use it

Take a look at my structure tutorial, I explain indentation there
Quote: "Well written code is indented into levels. When you use a command that consumes more than one line, you must indent the code within the opening and closing statements so that you can clearly see where one command ends and the next begins."

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

TDK
Retired Moderator
23
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 25th Jan 2008 20:13
Quote: "I don't like that program but if you really can't indent then use it"


Most people can indent - when they have been told about it. A lot of new coders are simply not told about it.

The purpose of my indenting program is to indent old code from before you knew how to do it.

We know how to indent code, but imagine going back to one of our early 1000 line programs which we hadn't indented and having to indent it.

DBA Tidy is for people who do know how to indent, but have code with lots of lines of code which is not.

I didn't write it to be a replacement for indenting your code as you go along.

Or do you like adding/removing lots of spaces to and from code?

TDK_Man

Sinani201
19
Years of Service
User Offline
Joined: 16th Apr 2007
Location: Aperture Science Enrichment Center
Posted: 26th Jan 2008 00:30
I hate to admit this, but I have no idea how to indent code. I never really understood how it works, so I just use DBA Tidy. I just write my code without indenting, and if I find an error that I don't know how to fix, or if I finished a program, I use DBA Tidy.

Seriously, how do you make the little blue text come up below your message?
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 26th Jan 2008 01:10
@Sinani
Look at my tutorial I think my explanation is clear.
If you have a DO LOOP then everything in between the words DO and LOOP is inside the loop, so you would indent everything in between DO and LOOP. Then if you had a FOR NEXT inside the DO LOOP you'd indent the code within FOR and NEXT adding another level of indentation.

Think of it like windows file explorer

See how the indenting clearly shows which files are contained in File A, and if we open File AB the same thing happens


So we could write a program like this
First we start with DO to begin our loop

Now lets add a FOR loop inside the DO loop

Now lets add some code inside the FOR loop

Now let's come out of that FOR loop and write some more code for the program

So written normally it would look like this


You get it now?

Sinani201
19
Years of Service
User Offline
Joined: 16th Apr 2007
Location: Aperture Science Enrichment Center
Posted: 26th Jan 2008 01:16
Yeah... I guess so...

Seriously, how do you make the little blue text come up below your message?
TDK
Retired Moderator
23
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 27th Jan 2008 03:15
Essentially, you move the start of all lines of code inside a programming 'block' two (some people like three) spaces to the right. With lots of nested loops however, I find that three can push text off the screen on the right side.

I define a 'block' as a number of lines of code with a defined start and end line.

Do..Loop is a prime example. 'Do' defines the start of the block and 'Loop' defines the end, so all lines between should start two spaces to the right.

Other loops like For..Next, While..EndWhile, Repeat..Until should be indented as well as it makes them stand out and easier to see. And when you can see them easily, you can spot missing closing lines which cause nesting errors.

If..Else..Endif blocks are also indented for the same reason and I also indent Open File blocks too - since they too have a defined code block end with 'Close File'.

In short, whenever you add a line of code which requires an associated line to end that section, then the following line(s) should be indented.

TDK_Man

demons breath
22
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 30th Jan 2008 15:32
hmmm... I tend to use tab instead of 2 spaces. Oh well it doesn't cause too many problems because I never use that many nested loops; there's only so many you need to make hello world & similar programs...

"A West Texas girl, just like me"
-Bush

Login to post a reply

Server time is: 2026-07-05 09:06:09
Your offset time is: 2026-07-05 09:06:09