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 / Tutorial - Help on Debugging

Author
Message
Slayer93
20
Years of Service
User Offline
Joined: 5th Aug 2004
Location: I wish I knew
Posted: 25th Jan 2007 03:43 Edited at: 26th Jan 2007 00:09
I thought I would write a little tutorial on how to debug your game. This won’t guarantee that you will fix whatever problem you have but it should make it easier to find problems that you have. This is also from experience so if you think something seems wrong, if I should add something, or if there is an actual term for some of these words (yes I am making up words for a lack of a better term) do tell .

First off there is pretty much three kinds of problems you could have in your project – Run-Time Error, Syntax Error and Logical Error. A Syntax Error is when you write the command wrong, you don't have enough parameters, or it isn't the right data type. Thanks to an IDE though it will not highlight the command so it is easy to pick out. A Run-Time Error is basically an error that stops your code from running. A Logical Error is when your problem does run but it doesn’t do what you want it to do, example – Object AI should move around the waypoints but doesn’t.

Here are some general things you can do to help solve your problems.
1. Indent your code – this will make your code easier to look at and easier to follow. The way I indent my code is indent if/endifs, case/endcase, select/endselect, loops, and functions. Just look at this and tell me what looks better

This-



Or this-


Hopefully you said the second one if you didn’t never post your code on this forum EVER!

2. Don’t use GOTO. They make your code messy and hard to follow because it jumps everywhere. You should use functions instead because they are more organized and your variables are not global, unless you want them to be, and you may reuse the same variable.

Now you should create a set of debug functions. These functions will store any
information that you need to solve your problem, if done correctly. Basically the functions will get any information that gets sent to it and writes it into a file. The information can come from other functions, variables, arrays, ect. I’m not going to make these functions for you because I go by “No one understands your code more than you”. Although I will give some pseudo-code



As you can see there is an array called debug() and that holds any debug information throughout project. The info will be written to the array using _debug() and it will be exported using export_debug(). There is also one example function that loads an object. If you get an error because the object doesn’t exist you could just check the debug.txt and you will find out right away what happened. This could solve any Logical or Compiler errors, if done right.
If you don’t want any Run-Time errors, or close to any, then never use hard coded values for object numbers, image numbers, sprite numbers, ect. Instead use a function to find the next free number.

Ex –



The best way to solve logical errors is to just think it out. All code does really is to act out the commands so its all logical which is why the rnd() command really stinks. The Debug functions should also help by writing what happens in the function and then see where your logic went wrong although if you know there is no problem with your code then its probably a bug with the compiler but its probably not to likely.

Hope this tutorial helps anyone. I will probably write some more tutorials if this is any good so once I can finish my site I can put a bunch of tutorials on it . I also hope I didn’t miss anything since it took me about an hour to write this.

Working on Boxed for NVIDIA compo. Check it out

Hammaman
20
Years of Service
User Offline
Joined: 11th Feb 2004
Location:
Posted: 25th Jan 2007 13:44
Hi,

I think this is a useful starting point to help newcomers to debug their programs.

Firstly, can I point out an error in the code snippet. The function _debug(string) has a typo and should read:



I think it would also be useful to give a bit more detail as how to use these two functions (_debug and export_debug).

Firstly, I think you need to define an array - this simply means adding the following code at the start of your program



Then you can add the two functions at the end of your program. You will need to ensure that there is an End statement between the end of your program and the start of the function code (otherwise, DB/DBPro will do odd things when it reaches the end of your program).

Next, I would suggest you call the _debug function from the code as Slayer93 suggests, i.e. as you create new objects, or load them in, or reach a certain point in the code, etc.

If you want to call the _debug function to show you the value of a variable - e.g. x position, etc., then you will need to convert the number (be it an integer, float, or other type) to a string. I can't recall the command off the top of my head (I'm at the office at the moment), so I'll post this in later.

SO what you will create is an array which contains all your debug messages, but you will then need to call the export_debug function to create the text file called debug.txt (stored in the same directory as your DB project, I think).

When this is done depends on what problems you are experiencing with the program. For example, if you can't see the object, then I'd stick the export_debug function call, i.e.



in your program before the main game loop (which usually looks like:



and then you can check everything is as it should be before the main game loop starts.

If there is something weird happening during game play, then you may want to call the export_debug after the game loop when you've pressed (say) the escape button and the main game loop has finished.

Finally, it's worth saying that typos in variable names tend to cause the most frustration when it comes to debugging, so if the code is not doing what you expect, double check your spelling! DB and DBPro both have the habit of assigning a value of zero to any new variables they come across. So you may set missile_x to be 70, but if the code refers to misille_x, then it will use a value of zero.

Hope this helps.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 25th Jan 2007 14:26 Edited at: 25th Jan 2007 14:27
Some useful information here. One thing I would say though, is this:

Quote: "...so its all logical which is why the rnd() command really stinks."


There is no such thing as a standard user, and so your game will always be random - otherwise it would be a non-interactive demo! Randomising data is a basic feature of most games, and you need to be able to deal with it.



Code Dragon
18
Years of Service
User Offline
Joined: 21st Aug 2006
Location: Everywhere
Posted: 25th Jan 2007 22:08
Actually, there are 3 kinds of problems code can have:

Syntax errors
Run-time errors
Logic errors

Syntax errors are usually not a problem because the complier tells you which line is messed up. Run-time error is the formal term for complier error by the way.

Keyboard not found. Press F1 to continue.
Slayer93
20
Years of Service
User Offline
Joined: 5th Aug 2004
Location: I wish I knew
Posted: 26th Jan 2007 00:04
Quote: "
Firstly, can I point out an error in the code snippet. The function _debug(string) has a typo and should read:"


Thanks for spotting that will fix it now

@Hammaman

Quote: "
I think it would also be useful to give a bit more detail as how to use these two functions (_debug and export_debug)."


I will also try and explain the code a bit more.

Was the rest of your post directed to me or to add on to my tutorial. If it was directed at me, its psuedo-code and I never said it would work .

@BatVink

Quote: "There is no such thing as a standard user, and so your game will always be random - otherwise it would be a non-interactive demo! Randomising data is a basic feature of most games, and you need to be able to deal with it."


Never thought of it that way, although aren't most games random because of the player therefore it uses logic to act based on the player. Hope that made sense

@Code Dragon

Quote: "Actually, there are 3 kinds of problems code can have:

Syntax errors
Run-time errors
Logic errors"


I was combining Syntax and Run-time errors into Compiler errors but I guess it doesn't make to much sense if compiler error has a better term(Run-Time error). So I'll change that little bit up.

Thanks for the input guys

Working on Boxed for NVIDIA compo. Check it out

Hammaman
20
Years of Service
User Offline
Joined: 11th Feb 2004
Location:
Posted: 26th Jan 2007 14:06
@Slayer93

Whilst I don't want to muscle in on your work, my comments were intended to add to your tutorial. Please feel free to incorporate as much or as little as you wish - I was merely trying to assist other newcomers. I know from experience that it can be very frustrating trying to work out why your code is not doing what it should.

... and yes, I intended that my "pseudo-code" was merely an example to illustrate the points I was making (and so shouldn't appear as "code").

Finally, trying not to contradict my first remark of this post , there is always the method of simply printing out the value of a key variable on screen, e.g.

print "Missile x = ";missile_x

(where I've assumed that missile_x is the variable you are interested in).
Slayer93
20
Years of Service
User Offline
Joined: 5th Aug 2004
Location: I wish I knew
Posted: 30th Jan 2007 01:22 Edited at: 30th Jan 2007 01:23
Wierd this post showed as read but when I went into the thread to post I saw yours. Sorry for not posting early, I think I will add in your contribution but not here, on my site(I came to post about it). I will add the tutorials sometime this week.

Anyway the reason I came is because I just finished making my site. Pretty proud of it since this is the 2nd time I didn't use tables to position my site and used CSS(first time was a horrible attempt but it still worked) and this is the first time I used php and mysql in a site.

Here is the link, I will be updating the site to put up many of my projects, code snippets, ect., http://www.slayer93.galekus.com/Slayer93/index.php?page=1


Any suggestions for my site, would love to hear them

Edit: I would also appreciate comments about the tutorial too. I want to make it perfect!

Working on Boxed for NVIDIA compo. Check it out

Login to post a reply

Server time is: 2024-09-25 17:32:49
Your offset time is: 2024-09-25 17:32:49