First of all I disabled "automatically insert closing block statement" in options>text editor, because it messes your code really bad.
Now if you want some advice about how to make your code easier to read and debug, I can explain how I manage my code. But it doesn't mean you have to do the same.
1) You can divide your code into a few source files: main.dba for main program, PlayerControl.dba for player, LoadStuff.dba for loading Your content and so on. It is easier to find your functions this way, but I am not using this because when you get a runtime error, it doesn't show you the right line of error. Or at least it doesn't work on some old version of compiler that I was using year ago.
2) As nonZero mentioned, reusable functions are necessary. I started learning DBP by making an RTS game. It is not finished, but I rewrited everything in different structure for 3 times. Now I am up to RPG style game, and I used lots of functions from RTS. Something like setups, loading maps, selecting, moving objects- it is all reusable.
3)If you write a long long function, try to break it into smaller pieces. It will be easier to debug, because You need to find a problem in shorter piece of code. In 40 lines length function there may be many dependancies, many variables, if statements and other stuff. But you can cut away some code and place it in separate function. Then it will be easier to track down the bug, and code will be easier to read as You have less nested statements
If You have any nabish questions, I will be happy to answer. I can provide some code snippets too. For RTS or RPG. Control of objects, menus, loading media...
Here is a summary of my current project:
Constants
Variables
Types
Arrays
`Program start:
Setup program (window,display mode, etc)
Load images
Main menu (select which character to play)
LoadModels
LoadSounds
TerrainSetup (creating game world)
MakeTrees
MakePLAYER
MakeMobs
`main loop:
Get time, input Parameters
Interface (mouse input, you can access main menu from here)
UpdateWorldInfo (check current state of world)
PLAYERcontrol (control player with buttons)
AIcontrol (determine what NPC should do next)
UpdateCHARS (set animations corresponding to what characters are doing)
Move objects
if it is time to redraw scene
info (show some debugging information)
sync (redraw)
endif
`end loop
`Program end
All functions
Join The dark Side! We have cookies