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 / Mysterious Loop Error

Author
Message
Arcmage
14
Years of Service
User Offline
Joined: 20th Apr 2010
Location: Pluto
Posted: 21st Apr 2010 06:15
Hello, I am relativity new to DBP. I have read almost all the tutorial posted here (several times) and decided to start working on my own simple game. I designed the game on paper and started working and within half an hour I already had a mystery Error (to me anyway).

My Problem is that the code does not take input this is caused as far as I can tell because the loop stops running In my own effort to debug it I added in print statements to check the X and Y values I was trying to manipulate and although I could not change it with the input by adding Inc Main.X to the loop I was able to see them go up to about 2000 and then stop which is why I think the loop is ceasing to run. Here Is the code (Please Excuse my grammar I am a student)

Any Incite would be appreciated
luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 21st Apr 2010 10:17 Edited at: 21st Apr 2010 10:29
There is your code rewriten by me where was needed:



I have few thing i need to say to you.

First get rid of goto and gosub`s, this way of coding leads to bad habit using this commands which will most certainly let you down.Even in small test aplications you need to avoid using them.You`ll do favor to yourself believe me.

I don`t know but there is something wrong with tutorials in DBPro.Every newbie start with this bad habit using goto and gosubs.It happend to me also, and really fast abandon them.

Instead of using "print" command where is possible i prefer "text" command because it gives more freedom, you can place the text wherever you want.

Something very very important is to learn about how syncing works.Because you used "sync on", the program expect you taking care of syncs and there is no syncing at all in your program.Using sync off instead will make your aplication sync when it`s needed.When do use "sync on", be sure to put a "sync" in the end of your main loop.

Your keystates: WRONG!
I don`t know where you get this values and who told you that they was representing WASD controls.You can use CTRL+K for keystate helper or use Tools>Keystate Helper on the menu.It can give you right values when you hit a button.It produce even ASCII codes, if you needed them.In the past there was no keystate helper and i made program to produce values for me.It involves scancodes.Read about it.Try to make one Keystate Helper for yourself, to see how things work.

EDIT: About your WASD controls i just assumed you want them to do what i made them to do, you can invert them if that`s not the way you need them.

Best regards!

Where there is a will, there is a way.
I often edit my posts, that`s who i am
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 21st Apr 2010 21:12
Quote: "Every newbie start with this bad habit using goto and gosubs."


I'd just like to point out that yes, Goto is bad but Gosub is good! (Hopefully, that was just a typo on luskos part)...

Using functions for everything is simply the wrong way to use functions. They were simply not designed to be used in that way:

http://forum.thegamecreators.com/?m=forum_view&t=96505&b=7

(We can discuss the pros and cons of my argument in that thread if you disagree with me)...

Having said that, using nothing but functions does work and if it's a choice of a program with all functions or using just Goto, then as bad as I believe it is, using all functions wins hands down.

Quote: "I don`t know but there is something wrong with tutorials in DBPro."


I think it's quite important too and I probably go a bit over the top going on about it so much in my tutorials.

However, as they are linked to from a sticky on the DB Classic board, I think they get missed by many newcomers to DB Pro - the reason I must annoy people by posting links to them on here so often!

TDK

Arcmage
14
Years of Service
User Offline
Joined: 20th Apr 2010
Location: Pluto
Posted: 22nd Apr 2010 02:20 Edited at: 22nd Apr 2010 04:17
Thank you for the help Sync has been confusing me for some time but I think I finally got it. I originally used prints do to not knowing about the str$() command that also is very useful. I used a diagram from the internet for the key states I guess it was incorrect.

I have another glitch should I post it here or on a new thread?

I added some stuff to the code including a simple mathematical collision system but its is extremely buggy Here is the new code (The Glitch is in the handle events function).



I am not sure if I am just getting + - y and x mixed up or if its something more problematic I tried several different combinations but it seems that DBP does not use the same x and y as a normal mathematical 2d plane.
luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 22nd Apr 2010 09:35
Try few tutorials as TDK said there is no need everything to be made with functions.That`s why i moved your WASD controls in the main loop and you just make it again in function.Read about how to use them like they should be used.What content can have and what not.There is simply some stuff you can`t make with functions.Some stuff you can achieve hardly, and other that are best done with functions.

Where there is a will, there is a way.
I often edit my posts, that`s who i am
Arcmage
14
Years of Service
User Offline
Joined: 20th Apr 2010
Location: Pluto
Posted: 23rd Apr 2010 02:55 Edited at: 23rd Apr 2010 05:40
In my opinion whether or not to put the code into functions or not is more a question of individual style rather than a question of efficiency . I like having the controls in a separate function so I can easy copy them over to a different project and because It keeps the main loop short. I believe TDK was commenting on how using Subroutines as well as Functions was a good idea although I don't think it matters much in this circumstance. Also what do you mean by "Try few tutorials" I have already read most of the tutorials on the links page.

Back on topic I managed to improve the collision code somewhat but its still very buggy is there a better way to do 2d collision?

Edit: Never Mind I fixed it Still wondering If this is the right place to post another question and if this is the most efficient way to do it though.

Login to post a reply

Server time is: 2024-11-23 17:19:59
Your offset time is: 2024-11-23 17:19:59