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.

Newcomers DBPro Corner / Code errors in loop hell - new to darkbasic.

Author
Message
300happy
16
Years of Service
User Offline
Joined: 21st Feb 2008
Location: Indiana, USA
Posted: 23rd Feb 2008 02:36
Hi, I'm new to both this forum and the Darkbasic language. I coded in old Qbasic back in the days, and have been learning various other languages since then, so I'm not new to the logic behind coding, just the language and it's nusiances.

Below is some gravity code I've been trying to compile, written by me, of course. I'm not sure why, but it's been throwing compiler errors at me everytime I build it, and the errors always are on the lines with the if loop statements or the endif statements.

If someone who knows the way DB thinks and what keywords are allowed in combinations could take a look at this script, I'd appreciate it.

The only two objects in the scene are object 1, my hero "happy", and object 2, the level geometry. My other, position based collisions worked fine, but don't calculate any gravity forces.

And, yes, I know this will result in him endlessly bouncing due to the reverse of his Yspeed at the end of the loops. It's only temporary, as a test for roof and floor collisions without needing to worry about a jump command yet.

Anyway, this code is in my main loop:



Thanks in advance for any help you can provide. Or even an easier way of doing this, if there is one. Lord knows this is an awful messy way of doing gravity.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 23rd Feb 2008 02:48
happySpeedY=Gravity+happySpeedY < Not so good
Inc happySpeedY#,Gravity# < Better

if object collision(2,1)=1 then < Wrong!

If object collision(2,1)=1 < Right!
Endif

else if happySpeedY<0 then < Wrong!

< Right!

if hitRoof=1 or hitFloor=1 then < Wrong!

if hitRoof=1 or hitFloor=1 < Right!

TDK_Man

300happy
16
Years of Service
User Offline
Joined: 21st Feb 2008
Location: Indiana, USA
Posted: 23rd Feb 2008 03:27
Ok.

I take it the THEN keyword is not needed in an if statement? What is it for then? The manual says to make sure the lines after the THEN statement are seperated by a :, implying that I am supposed to follow every if with a then. But then again, the manual is often useless with it's syntax examples, and the example code provided is too confusing to new people since it contains a bunch of stuff needed to run a demo instead of a simple example of a possible use of the command. Either that or I'm just missing something somewhere.

Now I get an error on the very last line, the LOOP command.

I'll post all my code in the main do loop. It's long, but I guess it can't be helped.



The last line is marked as an error, even though I think it should line up with the DO at the top of the loop, right?

I'm still a bit confused how DB handles embedded loops. The documentation unfortunetly doesn't seem to say anything about it either. What determines which "close this loop" command is attached to which "start this loop" command?

Again, thanks for your time, and for helping this new goofball of a DB coder learn a thing or two.
Paul08
16
Years of Service
User Offline
Joined: 20th Feb 2008
Location: Oxford, UK
Posted: 23rd Feb 2008 21:10
but what is the output of the compiler, what is the error text?
Paul08
16
Years of Service
User Offline
Joined: 20th Feb 2008
Location: Oxford, UK
Posted: 23rd Feb 2008 21:12
double post but:
http://forum.thegamecreators.com/?m=forum_view&t=64198&b=7

theres something on loops there, something on a lot of things actually - quite useful. aswell try TDK's tutorials they are stickied at the top of the newcomers forum.
300happy
16
Years of Service
User Offline
Joined: 21st Feb 2008
Location: Indiana, USA
Posted: 23rd Feb 2008 21:51
Well, after some sleep I found the problem. I had forgotten to close one of my loops. Typical error.

Anyway, I can't figure out why he's not bouncing the same height each time. I know physically he shouldn't if a collision simply reverses him, but I set a value called "happyBounce" to 100, and when he hits the floor he should end up flying upwards at speed 100, which should result in him always bouncing 100 speed above whatever terrain he is on.

However, as you can see by running my project, this isn't the case.

I've attached my whole project files in a zip. I don't have a clue what could be happening anymore. It's almost like something is setting his max height to a value, but I don't see anything that would do it in my code.

Could someone take a look and tell me what might be wrong?

In the meantime, I'm going to take a break from this project and try some other things in a fresh project. Probably some 2d sprite commands or something easier like that.

Attachments

Login to view attachments
PresFox
19
Years of Service
User Offline
Joined: 28th Aug 2005
Location:
Posted: 23rd Feb 2008 22:03 Edited at: 23rd Feb 2008 22:03
the then is only needed if you keep all if commands after if on the same line, eg

if a = 1 then a = 2 : b = 1

does the same as

if a = 1
a = 2
b = 1
endif

Microsoft isnt evil, they just make really crappy operating systems -- Linus torvalds
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 24th Feb 2008 07:59
Try DBA Tidy (downloaded from here):

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

As well as being a source code formatter (adds/corrects indentation), it has the side effect of clearly showing up nesting errors.

After a while of using DBA Tidy, you'll get used to spotting them yourself...

TDK_Man

Paul08
16
Years of Service
User Offline
Joined: 20th Feb 2008
Location: Oxford, UK
Posted: 24th Feb 2008 18:18
works fine mate, just change your code a bit from:



to


i found that does the trick, object has collision and then runs the above code.. and then obviously repeats.

+1 is not very much movement i dont think, is this what you were expecting?
Paul08
16
Years of Service
User Offline
Joined: 20th Feb 2008
Location: Oxford, UK
Posted: 24th Feb 2008 18:35
anyway i've made some changes to your code (im a newbie and like to play), i think this works quite well:






-try that, to get onto your "map / world" you need to "jump" a few times as you go as the collisions method isnt great at the minute..

hth,
Paul
Paul08
16
Years of Service
User Offline
Joined: 20th Feb 2008
Location: Oxford, UK
Posted: 24th Feb 2008 18:47
last post from me, i've actually zipped up the contents of a modified game code now, sorry, but i had to make some changes to his movement etc as it was a bit annoying.
the code wont make sense in the sense that the "move object -1" command is back to front - i think thats because you've exported your object (mr happy) back to front?

anyway i'll leave this on my web hosting for a day or two for you.

http://e-swoosh.co.uk/art/game.zip

(sorry for so many posts, but im not patient enough to wait for my others to come through)
300happy
16
Years of Service
User Offline
Joined: 21st Feb 2008
Location: Indiana, USA
Posted: 25th Feb 2008 21:14
Oh, that code is helpful for showing me a few ways to do things Paul08, but it's not what I was trying to do.

I'm trying to make a "bouncy ball" effect when he hits the ground. I know this won't make sense with this character, but he's a placeholder graphic for later, when I get the ball textures and rotations working.

Basically, I'm trying to get a bouncy ball that will endlessly bounce. Every time it hits the ground, it needs it's bouncyness to be set to a certain adustable value(this is for later use when materials and such come into play). So what I really am trying to do is simply send happy back upwards at speed X whenever he hits the ground, subtract the gravity from his speed each loop(which will result in him coming back down sometime eventually), and then if he hits a roof instead of the floor(in other words, his speed is still going upwards when collision takes place), send him back down by reversing his speed value to simulate a "proper" or "real life" bounce.

Now that I think about it, I'll probably just start from scratch instead of trying to salvage this code. I've been playing around with functions, and I'll probably need to apply these physics to other objects later in development. My code is such a mess anyway, being my first project and all.

These tools and examples certanly helped me learn a bit more about DB scripting. I'll call this a learning project and try again with a clean slate. Thanks for the help.
Paul08
16
Years of Service
User Offline
Joined: 20th Feb 2008
Location: Oxford, UK
Posted: 26th Feb 2008 15:15
Hey im doing the same thing, except my first project was a cube.

im trying to get it right from the begining with functions and a bit of structure - really helps put a final game together just calling functions at the right time.

just experiment really thats all im doing - sometimes it works and sometimes you fail miserably!

good luck
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 26th Feb 2008 20:16
Quote: "sorry for so many posts, but im not patient enough to wait for my others to come through"


The sooner you are off post approval the better then!

TDK_Man

Paul08
16
Years of Service
User Offline
Joined: 20th Feb 2008
Location: Oxford, UK
Posted: 26th Feb 2008 21:10
im off it now as you've probably noticed

..sorry

Login to post a reply

Server time is: 2024-11-25 07:57:58
Your offset time is: 2024-11-25 07:57:58