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.

2D All the way! / Nesting errors driving me bonkers

Author
Message
Plastico
22
Years of Service
User Offline
Joined: 3rd May 2004
Location:
Posted: 14th Jul 2004 12:00
wtf? whats with this darn nesting error I keep getting?



this is where its happening at my last loop, here is the full code.

zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 14th Jul 2004 12:35 Edited at: 14th Jul 2004 13:09
Urmmm,

You have two do...loops

take out the second do loop (all of this)
Quote: "
do
if spacekey() then end
` if returnkey() then goto continue

sync
loop
"


------------------------------------------------------------------
And in the second snippet you have the two do loops(No Good!) and A reapeat without a while staement.

Just get rid of the repeat command
You only need one or the other the way you are setting it up!


do
rem main loop
rem code ...
rem code ...
rem code ...
sync
loop

you can add the if spacekey()=1 then end if you would like.

Like this...


Final tips & remaining queations:
Now I don't understand why you are positioning sprite 1 twice per frame, and I am not at a computer with a compiler on it, so perhaps you can expalin that logic to me.


Plastico
22
Years of Service
User Offline
Joined: 3rd May 2004
Location:
Posted: 14th Jul 2004 13:11
I really dont know what it is im doing.

Im reading your rems now, and taking notes.
Emperor Baal
22
Years of Service
User Offline
Joined: 1st Dec 2003
Location: The Netherlands - Oudenbosch
Posted: 14th Jul 2004 20:22
zenassem, that's sooo untrue. You can use as many do-loops as want.

I've recoded ye code, plastico:



zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 15th Jul 2004 03:20 Edited at: 15th Jul 2004 03:43
Emperor,

I went back an edited some comments out, In which I stated the "Way you are trying to use them". I had replaced that statment with "The way you are setting it up". Before you saw the post.

Quote: "You only need one or the other the way you are setting it up!
"


He basically had

repeat
do
....
loop

do
...
loop

With no condition to break from the first loop wo the second. So hence, the second do loop would never execute. That's what I meant about not having two do loops; "In the context he was using them!"

If you look at his code it was not his intention to have the two do loops and a repeat with out a while. He was trying to set up a main game loop. And I believe the things I pointed out fixed his original nesting error question. Nuff Said.

Second you didn't use a pure Do loop. You used While loops. And both while loops are checking the same condition. At that rate you could throw a while loop at every line in the program. Though I don't think it would necessarily help him understand the idea of a main game loop. In addition, you left the variables in the loop so that they will be reset each time, doesn't make much logical sense, that's why I tried to pull certain things outside the main loop.

Well enough of splitting hairs, I think you understand what I was trying to inform him about, in the context that the code was posted.

Last, I am not at a computer with my DBpro compiler so I just tried to clean it up the best I could with what I imagined he was looking to do. There are numerous ways to re-write the code.

~zen


Emperor Baal
22
Years of Service
User Offline
Joined: 1st Dec 2003
Location: The Netherlands - Oudenbosch
Posted: 15th Jul 2004 03:41
Quote: "You used While loops. And both while loops are checking the same condition"


And?

Plastico
22
Years of Service
User Offline
Joined: 3rd May 2004
Location:
Posted: 15th Jul 2004 04:28
Both of you are experts in what you do, I am a newbie, hardly knowing an array from a string. I like to fool around with different things here, and hope that people help me along the way. Thank you, all this info helps me greatly.

zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 15th Jul 2004 06:57
Sorry Plastico,
Sometimes that happens in threads.

I think that we were both trying to help. What Emperor Baal said is true you can have, more than one loop; I was trying to avoid a confusing answer.

I hope that both examples will provide you with things to try and discover.

Please post if you have any other questions. desisgning a good gameloop can cause confusion, especially when the main loop contains other nested loops.

~zen


Plastico
22
Years of Service
User Offline
Joined: 3rd May 2004
Location:
Posted: 15th Jul 2004 07:41
one more question. I changed the upkey and downkey to a slower pace.(instead of 5, i used 2) now, to make the object not go off of the screen, do I make an array? or am I thinking of the wrong thing here.


IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 15th Jul 2004 08:04
Just a set of simple if statements are all that you need. Just place the following lines after the key input routines



If you are using a larger display than 640x480 then you will need to adjust the code. In fact, you will need to adjust the values anyway to take into account the size of your sprite.

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins, source and the Interface library for Visual C++ 6, .NET and now for Dev-C++ http://www.matrix1.demon.co.uk
Plastico
22
Years of Service
User Offline
Joined: 3rd May 2004
Location:
Posted: 15th Jul 2004 09:38
having my if x> set at 639 is perfect so that my ship doesnt go off of the screen. but 439 is letting me go to far. what is the default screen size for DBpro?
Plastico
22
Years of Service
User Offline
Joined: 3rd May 2004
Location:
Posted: 15th Jul 2004 09:39
nvm figured it out. thank you Ian

Login to post a reply

Server time is: 2026-06-09 19:41:06
Your offset time is: 2026-06-09 19:41:06