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 / nesting error!! WHERE IS IT!!

Author
Message
Fast and Furious
17
Years of Service
User Offline
Joined: 23rd Jul 2007
Location: inside that dog
Posted: 12th Sep 2007 01:56 Edited at: 12th Sep 2007 01:59
O.K. Im having some trouble with my first videogame, I can't find out where this stupid nesting error. Heres my code.Can you help me?


please no bad comments,its my first game
I hope you can help me out.
the loop is in bold because thats where the nesting error is
luke810
18
Years of Service
User Offline
Joined: 4th Sep 2006
Location: United States
Posted: 12th Sep 2007 03:33
This is not a bad comment, but a helpfull suggestion. Indent! I doubt anyone is going to read through that. Why don't you download TDKs code tidier program.
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 12th Sep 2007 10:59 Edited at: 12th Sep 2007 10:59
Quote: "if bulletlife>0 dec bulletlife move object 20,30000000000 if bulletlife=0 then hide object 20 for crazy=0 to 10 point object 20,rnd(crazy),rnd(crazy),z#-2 next crazy if shiftkey()=1 then dec reload1 : ammo=200 if (mouseclick()=1 and (timer()-shotbuffer> shotdelay) and ammo > 0 endif return"


This is the nesting fault..Should be Endif Endif Return

Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 12th Sep 2007 13:04
@Pincho
I don't think you should have answered the question after Luke said he should indent his code.

@F&F
Indenting is good practice, and it helps others to follow your code.
Have a look at my tutorial on code structure

In programming, nothing exists
SimSmall
20
Years of Service
User Offline
Joined: 7th Aug 2004
Location: United Kingdom
Posted: 13th Sep 2007 00:57
Quote: "I don't think you should have answered the question after Luke said he should indent his code."


Why not? Point of principle? He found the error so why not point it out...

I do agree with the indenting thing though. Had the code have been indented you would have known exactly where the problem was anyway
Fast and Furious
17
Years of Service
User Offline
Joined: 23rd Jul 2007
Location: inside that dog
Posted: 13th Sep 2007 01:05
now the loop isn't where the nesting error is any more
it's now at next bam#(in bold)

Quote: "I doubt anyone is going to read through that."

Heres my code spaced out



the next bam# is where then problem is

thanks
demons breath
21
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 13th Sep 2007 01:34
indenting is where you lay out your code like this:



that's what you need to do - just press tab at the start of lines to indent them once, and then indent again for if you have another statement nested inside that one...


also it's "an alien spaceship" not "a alien spaceship"

http://jamesmason01.googlepages.com/index.htm
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 13th Sep 2007 02:50
@Fast and Furious

Please follow demons breath's indenting example. It will help you organize your code and find bugs, and anyone else that is trying to help.

Two things I noticed in there, you have a NEXT q# that is out of place. It comes before three other NEXTs from for next loops that you set up - so that qualifies as a nesting error. You also have a function in the middle of your program. This will cause problems. For DBC, include all of your function declarations at the end of the program following the END command.

ex:



Enjoy your day.
Fast and Furious
17
Years of Service
User Offline
Joined: 23rd Jul 2007
Location: inside that dog
Posted: 14th Sep 2007 01:22
I hope this is good enough

I tweaked it alot and now the nesting erreo is at the very bottom
at next alienall# next alien2# and next alien#



luke810
18
Years of Service
User Offline
Joined: 4th Sep 2006
Location: United States
Posted: 14th Sep 2007 01:28
Wow that was done horribly incorrectly.

Read the tutorial obese suggested. You're not supposed to put indents every other line, there are guidelines to follow.
Fast and Furious
17
Years of Service
User Offline
Joined: 23rd Jul 2007
Location: inside that dog
Posted: 14th Sep 2007 01:35 Edited at: 14th Sep 2007 02:03
well this stinks



oh well

Edit:I just don't understand it
you gave me an example BUT how do you use it
like how many times do you indent the elses or the endifs or the loop or all the good stuff inside those ifs plus the gosubs
just give me a little more detail and then I'll help you out so you can help me out.

*keep on gaming*
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 14th Sep 2007 03:00
@F&F
Quote: "just give me a little more detail and then I'll help you out so you can help me out."

Have a look at my tutorial on code structure.
I already posted it once!
Once you have that sorted out your code will be a lot less daunting

@Sim Small
Quote: "Why not? Point of principle? He found the error so why not point it out..."

The point is that Pincho, although being helpful, kind of overruled Luke810 and made him look like an jerk.

@Pincho
I'm amazed that you looked at that code and still took the time to go through it all! Have some beer

In programming, nothing exists
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 14th Sep 2007 03:15
Quote: "Why don't you download TDKs code tidier program."


Good question - well ignored!

http://forum.thegamecreators.com/?m=forum_view&t=104344&b=5

TDK_Man

Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 14th Sep 2007 03:18 Edited at: 14th Sep 2007 03:22
@TDK
but that's cheating
and anyway, indenting is useful as you are writing so using that cheat isn't going to help the coder, only after he has finished.

[edit]
Woah my tut has had over 700 views! Guess they're waiting for me to finish before they comment

@TDK again
How did you do your tuts, did they grow on here like mine is (slowly), or did you write them somewhere else and post in one go?
Got any tips for me?

In programming, nothing exists
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 14th Sep 2007 14:27 Edited at: 14th Sep 2007 14:30
Quote: "@Pincho
I'm amazed that you looked at that code and still took the time to go through it all! Have some beer "


I have programmed for 27 years, and I very rarely indent anything anymore. I started off indenting things properly, but then started speed programming, and writing games in 3 days, and skipped the indenting to do things faster. So I can read code that isn't indented without too much effort. I put spaces between some code segments, instead of indents.

Insert Name Here
18
Years of Service
User Offline
Joined: 20th Mar 2007
Location: Worcester, England
Posted: 14th Sep 2007 18:23
I don't indent. Ironically, to me indented code looks messy. Like someone had an accident with the tab key.

............................
Fast and Furious
17
Years of Service
User Offline
Joined: 23rd Jul 2007
Location: inside that dog
Posted: 15th Sep 2007 01:22
o.k. HERES MY CODE



Thanks TDK

*keep on gaming*
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 15th Sep 2007 06:10 Edited at: 15th Sep 2007 06:12
Certainly a lot easier to read now!

But, you can now see the main problem - you appear to have no idea what you are doing! Lol.

And I don't mean that in a nasty way...

There are many reasons your program is going to be trouble:

* Return is a keyword and should not be used as a label.

* You shouldn't load models from remote locations. Copy them into the project folder.

* You are using float variables which should be integers and then using them to store integers.

* You are loading bitmaps and grabbing images from them. Just use Load Image.

* You are creating matrix 1, texturing it and randomizing it a hundred times!

* You are using floats instead of integers in a For..Next loop.

* You have a Do..Loop inside a For..Next loop which will never be exited.

* You have procedures which are never called.

* You have main program code mixed inbetween procedures which can never be accessed.

* You have procedures after normal code that the program crashes into without being called.

* Most of your 'proper' Returns don't do anything because the procedures were never called so they will eventually just fill the stack and the program will die.

* You have many nesting loop errors. You can see this in DBA Tidy as the code should not be indented on the very last line.

The list goes on...

In short, it's a total mess and is way, way beyond any hope of repair.

In all honesty, your only hope is to bin it, read some tutorials and then start again because believe me, it will be a lot quicker and easier than trying to fix what you have at the moment.

Check out tutorials 1 to 4 here:

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

Tutorial 2 will show you how to set out a modular skeleton program so you have everything in the right place to easily add sections to it.

Tutorial 5 explains the difference between float and integers - basically when and when not to use the # symbol.

The rest of the tutorials will probably be of use later on for specific aspects of your game, but probably not for a little while...

TDK_Man

Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 15th Sep 2007 17:22
@F&F
TDK may sound harsh, but listen to him and you'll save a lot of time

@Pincho & INH
I don't believe that you find it easier to read unindented code, that just doesn't make sense.

In programming, nothing exists
Insert Name Here
18
Years of Service
User Offline
Joined: 20th Mar 2007
Location: Worcester, England
Posted: 15th Sep 2007 18:23
T'does. Having spent so long without indenting, I find non-indented code easier.

............................
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 15th Sep 2007 19:33
Quote: "@Pincho & INH
I don't believe that you find it easier to read unindented code, that just doesn't make sense."


I never said it was 'EASIER'.

Fast and Furious
17
Years of Service
User Offline
Joined: 23rd Jul 2007
Location: inside that dog
Posted: 16th Sep 2007 00:00


goodbye

Jack be nimble Jack be quick, Jack jump over the...FOREST FIRE
Insert Name Here
18
Years of Service
User Offline
Joined: 20th Mar 2007
Location: Worcester, England
Posted: 16th Sep 2007 00:25
Lo and behold, he can't take the criticism.

............................
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 16th Sep 2007 10:55
Quote: "Lo and behold, he can't take the criticism"


More the truth than criticism. He was probably fighting a losing battle trying to program inside a dog anyway...

TDK_Man

Insert Name Here
18
Years of Service
User Offline
Joined: 20th Mar 2007
Location: Worcester, England
Posted: 16th Sep 2007 22:19
Very true.
Another one bites the dust...

............................
Fast and Furious
17
Years of Service
User Offline
Joined: 23rd Jul 2007
Location: inside that dog
Posted: 16th Sep 2007 23:03
You know what..It's very relaxing programming inside that dog

@INH whats with the carrot?

Jack be nimble Jack be quick, Jack jump over the...FOREST FIRE
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 16th Sep 2007 23:30
@F&F
Have you started a new program yet?
Don't be put off; I found "Oli's Casino", a program I'd written about 4 years ago, it was my first proper program and I was so proud of it. It still works pretty well but the code is about 2000 lines long
with lots of GOTOs! (don't use GOTO ever ever ever)

In programming, nothing exists
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 17th Sep 2007 02:51
Fast and Furious:

Don't give up just because someone tries to set you on the right track. No-one expects you to know what you are doing when you first start, so you are bound to get lots of people telling you where you are going wrong. We all did when we first started.

It's better to be told early on about things like program structure and indenting your code because the longer you do it the wrong way, the more time you'll waste trying to get your programs to work. In fact, all but the smallest programs probably won't!

Programming is complicated and everything has to be 100% correct or things start going wrong. Discipline and good coding practices help to stop that from happening so they should be the first things you learn.

TDK_Man

Insert Name Here
18
Years of Service
User Offline
Joined: 20th Mar 2007
Location: Worcester, England
Posted: 17th Sep 2007 18:19
Quote: "@INH whats with the carrot?"

Ah... My tradmeark line. Good times, good times...

............................
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 17th Sep 2007 18:55 Edited at: 17th Sep 2007 18:55
Is the serdjo pic back?
[edit]
Ahhh you are using image shack now

In programming, nothing exists
Insert Name Here
18
Years of Service
User Offline
Joined: 20th Mar 2007
Location: Worcester, England
Posted: 17th Sep 2007 23:03
Yes. Mediafire let me down.

............................
Fast and Furious
17
Years of Service
User Offline
Joined: 23rd Jul 2007
Location: inside that dog
Posted: 18th Sep 2007 00:51 Edited at: 18th Sep 2007 00:57
Quote: "Have you started a new program yet?"

no I haven't I'm reading TDK's tutorials
EDIT:I mean I have been reading TDK's tutorials

Jack be nimble Jack be quick, Jack jump over the...FOREST FIRE
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 18th Sep 2007 00:54
Quote: "no I haven't I'm reading TDK's tutorials"

OK

In programming, nothing exists
Insert Name Here
18
Years of Service
User Offline
Joined: 20th Mar 2007
Location: Worcester, England
Posted: 18th Sep 2007 18:59
Good plan.

............................

Login to post a reply

Server time is: 2025-05-31 19:24:31
Your offset time is: 2025-05-31 19:24:31