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 / Can anyone spot my NESTING ERROR?

Author
Message
Junebug
13
Years of Service
User Offline
Joined: 19th Jan 2011
Location:
Posted: 19th Jan 2011 19:10 Edited at: 19th Jan 2011 21:10
My code:


When I run this code, it says "SYNTAX ERROR. NESTING ERROR AT LINE 422"
Your help is greatly appreciated, thank you to whoever can help
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 19th Jan 2011 22:08
In this section:



At around line 217 your for t has no next.

Enjoy your day.
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 24th Jan 2011 21:01
Hi Junebug,
Welcome to our little corner of the DB world.
I'd suggest using two spaces to indent rather than tabs.
I'd also suggest only indenting code inside a multi-line statement e.g.

I understand it can be helpful to mark out different sections of code but I would recommend finding another way to do that rather than using indentation, otherwise your code starts spilling over the page.


Everything worthwhile requires effort.
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 24th Jan 2011 23:37
Quote: "I understand it can be helpful to mark out different sections of code but I would recommend finding another way to do that rather than using indentation, otherwise your code starts spilling over the page.
"


Blank lines and REM commands work wonders for this. Sometimes just putting blank lines as physical separators can greatly increase readability of the code (though you don't really understand it much better, but that's what the REM's are for).

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Junebug
13
Years of Service
User Offline
Joined: 19th Jan 2011
Location:
Posted: 28th Jan 2011 18:43
Quote: "In this section:

+ Code Snippet
rem Steps
NumberOfSteps = 7
for t=0 to NumberOfSteps-1
make object box t+7,50,10,50
position object t+7,0,5+(t*20),100+(t*100)
texture object t+7,4
make object collision box t+7,-25,-5,-25,25,5,25,0

At around line 217 your for t has no next
"

yea thanks, but I had actually found that the same day I posted this.
Quote: "I'd also suggest only indenting code inside a multi-line statement e.g. + Code Snippet
rem Say hi.
for x = 1 to 2
print "Yo Junebug!"
next x

I understand it can be helpful to mark out different sections of code but I would recommend finding another way to do that rather than using indentation, otherwise your code starts spilling over the page.
"

yea I understand, that code is the template my teacher gave me in my video game design class, I just went with it.

Maybe someone can help me with collision boxes, it's really confusing me

I made the second set of stairs, yet only 1 stair appears. I'm making the 2nd set start at the top of the 1st set, but I want them to go negative on the x-axis, so going left, and going up like the first set but the collision box doesn't work
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 29th Jan 2011 14:49
Your teacher wrote that!?
Why do teachers still use capital letters and gotos everywhere?

Don't get me wrong, I'm sure your teacher is very knowledgeable but there are better ways to structure programs these days.


Everything worthwhile requires effort.
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 29th Jan 2011 15:41 Edited at: 29th Jan 2011 16:40
I don't know what you were trying to do here:

Are you trying to give the user a choice of which bitmaps to load?
At the moment it will try to load each bitmap until you interrupt by pressing a key, or if you don't press a key it will loop and then try to load them again causing an error.

I'll be writing a lot of small bits of code below, I think it's easier to read short code without code boxes, so for those small snippets I will put ## at the start of the line to indicate that it is code.

Bitmaps
When you load a bitmap you must give it a number:

## load bitmap "images/Tooth 3.jpg",3

So now when we use bitmap 3, dark basic knows we are talking about Tooth 3.jpg. Note that I could give the bitmap any integer number I wanted, but using 3 makes it easier to remember that this refers to Tooth 3.

Since numbers are used to refer to media, we could also use variables to refer to them:

## tooth3 = 3
## load bitmap "images/Tooth 3.jpg", tooth3

We have to be careful not to change the value of tooth3 if we're going to use it in this way; unfortunately DB (dark basic) doesn't provide constants - like variables but once set they cannot be changed.
I rarely use this technique myself, but it might help if you have lots of media and find it hard to remember what each number refers to.

Keystate and Scancode
Your statement to check if any key is pressed is clever but can be simplified:

## if keystate( scancode() ) = 1 then goto IntroLoopSection

This returns the scancode of the input to the keystate function which then checks if that key is being pressed. But if scancode returns a value then the key it refers too IS being pressed! So all we really need to do is test whether scancode returns a value:

## if scancode() > 0 then goto IntroLoopSection

Conditional Loops
Your DO loop cycles until a condition is met for it to jump to the IntroLoopSection label.
If you want a loop to break or repeat depending on whether a condition is met, use one of the three conditional loops, which I will now explain.

The repeat-until loop executes the code between its opening and closing statements, evaluates the expression given to until, and if true, breaks out of the loop and continues down the program.
Summary: a repeat-until loop repeats until the condition is true.

The while-endwhile loop tests its condition first and ONLY executes the code between the statements if the condition is true. Once it reaches the endwhile it loops back to the top and evaluates the condition again.
Summary: a while loop repeats while the condition is still true.

The for-next adjusts a counter variable until it is outside the limit you have assigned to the loop. For loops are actually just a type of while loop but using counters is so common that for loops are given their own special syntax. Here's a for loop:

and here's the same thing written as a while loop:

So you see FOR loops make this common task easier.

Back To The Code
Here's an edited version of your loop using everything I've explained (now we know that trying to load the same media twice causes an error I've moved the loading outside the loop).

Hope that helps you.


Everything worthwhile requires effort.
Junebug
13
Years of Service
User Offline
Joined: 19th Jan 2011
Location:
Posted: 29th Jan 2011 22:12
Quote: "Your teacher wrote that!?
Why do teachers still use capital letters and gotos everywhere?

Don't get me wrong, I'm sure your teacher is very knowledgeable but there are better ways to structure programs these days."


Yea, we're making this game in only 4 weeks or so, it's not like it's gonna matter how it's written, as long as it works.

Quote: "I don't know what you were trying to do here:
+ Code Snippet
Are you trying to give the user a choice of which bitmaps to load?
At the moment it will try to load each bitmap until you interrupt by pressing a key, or if you don't press a key it will loop and then try to load them again causing an error.
"

It's actually not creating an error, it's like an artificial .gif in the game, its just a loading screen but since I couldn't figure out how to insert a .gif file, I just put in each image individually and then made them load sequentially over and over until any key is pressed, if u run the code I have, it looks like a .gif of those 5 images.

And again, I'm not concerned with how my coding looks, I asked about those collision boxes, can you please help me with those sir?
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 29th Jan 2011 22:43 Edited at: 29th Jan 2011 23:28
Quote: "it's not like it's gonna matter how it's written, as long as it works."

Often these are one and the same thing, problems like your nesting error might have been easier to find if your program was easier to read.

Quote: "It's actually not creating an error, it's like an artificial .gif in the game, its just a loading screen"

Oh I see, sorry it has been a while since I used bitmaps and I forgot it pastes to screen if no number is given.
In that case you could do it like this:

I used a trick to exit both loops by changing one variable. When a key is pressed I force it to equal 8 (it is then incremented to 9 by NEXT bmp), we know it would only ever naturally equal 1-6 (remember the for loop only exits when bmp is outside the range so it would be 6 after the for loop) so we can be confident that if bmp is equal to any value outside the range 1-6 it must have been tampered with, in this case we know that a key has been pressed.

I haven't gotten your code working yet but when I do I'll see if I can give you some help with your collision boxes, unless another helpful soul comes along first.

[edit]

## make object sphere 8,100
## position object 8 ,0,250,900
## make object collision box 100,-50,-50,-50,50,50,50,0

Shouldn't that be 8 as well?

[edit]

The RGB command is quite slow so if you can it is best to store colour values outside the loop



Everything worthwhile requires effort.
Junebug
13
Years of Service
User Offline
Joined: 19th Jan 2011
Location:
Posted: 30th Jan 2011 00:02
Quote: "In that case you could do it like this:
+ Code Snippet"


I thank you for that
Quote: "
[edit]

## make object sphere 8,100
## position object 8 ,0,250,900
## make object collision box 100,-50,-50,-50,50,50,50,0

Shouldn't that be 8 as well?
"

yes, understand that I'm going through my code and changing things, cleaning it up, everyday, so I have indeed fixed that, it is now
## make object sphrer 200,100
## position object 200,0,250,900
## make object collision box 200,-50,-50,-50,50,50,50,0

Thank you for all your help, I appreciate it. Let me know when you have these collision box codes figured out, I'm depending on them by next Friday.
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 30th Jan 2011 00:13
Good job

Quote: "Let me know when you have these collision box codes figured out, I'm depending on them by next Friday."

What are you having trouble with? Do you have a book to learn from?


Everything worthwhile requires effort.
Junebug
13
Years of Service
User Offline
Joined: 19th Jan 2011
Location:
Posted: 30th Jan 2011 00:45
Quote: "Quote: "Let me know when you have these collision box codes figured out, I'm depending on them by next Friday."
What are you having trouble with? Do you have a book to learn from?"


afraid not, I have no clue how the codes work besides that the first 3 are the bottom front left corner of the 3D object and the next three are the top back right corner of the 3D object
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 30th Jan 2011 12:22
Quote: "I have no clue how the codes work besides that the first 3 are the bottom front left corner of the 3D object and the next three are the top back right corner of the 3D object"

Yeah that's right, and the last parameter is a flag to tell DB if you want the collision box to rotate with the object (set it to 1 for yes or 0 for no).
All this does is set up a collision box, it wont automatically deal with collisions. For that we need to use the OBJECT COLLISION command.

Do you have access to the help files? If not I have attached them to this post for you to download. --->


Everything worthwhile requires effort.

Attachments

Login to view attachments
Junebug
13
Years of Service
User Offline
Joined: 19th Jan 2011
Location:
Posted: 31st Jan 2011 18:36
I have access to the help files, they're in the help tab at the top, I really cannot figure out how to get the collision box to work with my steps


It's really confusing, plus I can only get 1 of those steps to appear.
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 31st Jan 2011 19:31
You seem to have changed the t's to g's and missed the ones in the position object parameters. That's why you only see one step, it is actually all 7 in the same position.

Have you looked up OBJECT COLLISION() in the help files? You need to use that command to test for collisions between objects.


Everything worthwhile requires effort.
Junebug
13
Years of Service
User Offline
Joined: 19th Jan 2011
Location:
Posted: 31st Jan 2011 20:01
Quote: "You seem to have changed the t's to g's"

wow, I cannot believe I did that.. well, there's still the issue of the collision box not working for those steps



the collision box should work, why isn't it?

Login to post a reply

Server time is: 2024-04-20 10:25:35
Your offset time is: 2024-04-20 10:25:35