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.

Dark GDK / Do/While Statements

Author
Message
Spooter
16
Years of Service
User Offline
Joined: 27th May 2008
Location:
Posted: 12th Apr 2009 03:09
When using this Do/While statement my Character instantly moves to his max height. It this just how the Do/While statements work... And if so how can I make this work.



/*================================================*\
| Lead Programmer/Owner===============Anti-Triangle Cult=====|
\*================================================*/
AndrewT
17
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 12th Apr 2009 04:23 Edited at: 12th Apr 2009 04:25
Basically your code enters a loop when the player attempts to jump. When a program enters a loop it remains in that loop until you either use 'break' statement or a condition is met. Your telling the computer to repeatedly move your player up until he reaches his max height--I'm assuming you don't want that. Instead just say:



This way the height is still increased while the player is below the max height, however it doesn't lock the program into a loop--once it moves the player up by 3 it continues to the rest of your main loop.

EDIT:

Now that I take a closer look at it--why are you decreasing the height? This is for jumping, no? Of course it could be in 2D. Nevermind.

i like orange
ABXG
15
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Canada
Posted: 12th Apr 2009 04:32
A do-while loop is a post-check loop. That means it does what ever is in the loop and than checks to see if the loop should be continued or broken. You also have to remember that your game is already in a loop. Basically what is happenning with your code is that you get to your loop, the loop completes and your character is at what ever location your loop would take your character to. Your problem is essentially that you are using nexted loops when you need to be using if-statements.

------------------------------------
Currently 900+ lines of code into an "over-the-shoulder" action RPG with combat based on rag-doll physics.
Spooter
16
Years of Service
User Offline
Joined: 27th May 2008
Location:
Posted: 12th Apr 2009 20:59 Edited at: 12th Apr 2009 21:00
Ok, I knew that you would say to use if Statements. So I was coming up with this while waiting for a reply



This is all wrapped up in a class. When I run the game with this code my guy moves up about 40 or so pixels and then instantly returns to the ground. I'm assuming their is a small problem somewhere in the code, or this just isn't set up right. Also you may notice I don't include a part where the sprite must return to the ground.. this is because I'm using a gravity function to make the sprites fall at a certain rate. If you want me to post it because that might be the problem, just ask.

/*================================================*\
| Lead Programmer/Owner===============Anti-Triangle Cult=====|
\*================================================*/

Login to post a reply

Server time is: 2024-11-25 14:48:35
Your offset time is: 2024-11-25 14:48:35