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.

DarkBASIC Discussion / Dealing With Code (a lot of code!)

Author
Message
Vinnie alt
20
Years of Service
User Offline
Joined: 15th May 2005
Location:
Posted: 26th May 2005 23:51
Hey..

Well I need some help with keeping track of my code. Now before you say it, I already use remarks and the GOSUB command and everything is neat and tidy, but I'm getting to the stage where I have got too much code, and finding what I want is impossable. I am currently using the Dark Edit interface, because it is so much more user friedly when writing a lot of code, but do any of you have any other hints or tips on how to keep track of code?

So can anyone help me out or got any ideas?

Thanks

-There are 10 types of people in this world, those who understand binary and those who don't.

-Wheres the "ANY" key?
Underworld 1020
21
Years of Service
User Offline
Joined: 2nd Mar 2004
Location: NY, USA
Posted: 27th May 2005 05:48 Edited at: 27th May 2005 05:52
Well, spacing can play a big part in organization, everyone has different methods. Here's some examples.

This is the way most pro's choose to code:

It basically has to do with nesting for like loops and If statments, and such, they just use the tab key. However, I really don't like coding like that, but you might.

Here's another way:

This is the way I usually code stuff, I use the tab key and colons to keep things organized, plus I usually use a GoSub a lot to keep my main loop as small as posible.

So, basically spacing helps a lot, choose which ever way works best for you. Thats really all there is spacing, gosub, and comments. Sometimes it is hard to find a piece of code out of hundreds of lines of code, but after a while you just get used to it .

SAnTA
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location:
Posted: 27th May 2005 06:28
Use functions, dark basic lists all your functions too assuming your using the project manager view. This is the same for most of the other IDE's too. This lets you flick between them easy. You can also close functions up out of the way when you are not using them.
waffle
22
Years of Service
User Offline
Joined: 9th Sep 2002
Location: Western USA
Posted: 27th May 2005 11:46
Try moving alot of your code to include modules ...
Use each module for specific purposes ....

Mapping
AI
User Input
Save/Load Functions
Internet
Memblock Wrapping Functions
String Functions
Math Functions
Other DLL wrapping functions
GUI manager

and so on.
TEH_CODERER
21
Years of Service
User Offline
Joined: 12th Nov 2003
Location: Right behind you!
Posted: 27th May 2005 18:20
If I understood what Waffle said then I agree with him.
You mean putting a load of functions into a seperate file and then using the #include command don't you?

Vinnie alt
20
Years of Service
User Offline
Joined: 15th May 2005
Location:
Posted: 27th May 2005 18:41
Thanks everyone!

I will take all your advice on board, and i think i will start using functions a bit more!

-There are 10 types of people in this world, those who understand binary and those who don't.

-Wheres the "ANY" key?
waffle
22
Years of Service
User Offline
Joined: 9th Sep 2002
Location: Western USA
Posted: 28th May 2005 09:19
Yes.
#include "string.dba"

or whatever.
I also like it for adding "new code".

There are some "gatcha's" though ...

1 - If using Dark Edit's preprocessor commands,
you will need to "replace source". This can cause problems.
So, first save your file, Then, save your file with an extra tag
example:
"stringDE.dba" - this would be Dark Edit Source code
"stringdba.dba" - the would be the "replaced Source"
The replaced source would then be ready to use as an include file.

2 - Since the code gets changed to make an include,
you will need to provide alot of documentation in your includes
as to how to use everything.

3 - Of course, you can simplify things just by not using the
preprossesor directives. After all,
Global AVar
just gets changed to
Dim AVar(1)

and
Type SomeType
Var1
Var2
EndType
Just goes to
Dim SomeType_Var1(1,50)
and so on

The Defines are nice, but don't always work either.


The way I manage "new code" is to place bookmarks (actually a line marker just like using a goto or gosub) at key points, and try to key new code in a function of its own. This helps with debugging.
We all know the bebugger gives errors from time to time, so,
work in a small area. Before moving to another area in code, try compiling. If it crashes, check your last changes. There is nothing more frustrating that making many small changes throughout your program, go to compile and have it crash to the desktop without no clue as to where to begin looking Keep changes localized.
comm_jak
20
Years of Service
User Offline
Joined: 31st May 2004
Location: FOB: Fields Of Battle
Posted: 29th May 2005 05:56 Edited at: 29th May 2005 05:57
I was trying to use the #include command but I don't know how. I was also trying to use the shell executable command because I had TONS of code so I made 2 different exe's and the first one was the main menu for my game, and when you clicked the "New Game" button it ran the other exe (which was my game). I didn't work for me so I then tried using the #include command but I didn't even know how to use that command so if anyone knows how to do what I was trying to do then maybe it will help you Vinnie alt in your game.

I will command the troops to victory
NanoBrain
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 29th May 2005 14:46
comm_jak,

The files you include must contain functions, just like any regular user-created function in DB. I usually make a 'driver' file, which links all of my include files together, and makes the game work overall.

So, look at the code snippets below. Copy and paste them each as a seperate .dba file, all into one folder. The first code snippet will be the 'driver', the one you need to execute.





Also, notice in the 'driver' file the variable 'frmfocus'. This can be used to run different menus at different times, instead of using seperate EXEs. That, if you seperate groups of code into seperate if statements, asking if a variable equals a certain value, then run this group of code. Then, you have a way to create seperate menus that appear on the screen.


+NanoBrain+
Vinnie alt
20
Years of Service
User Offline
Joined: 15th May 2005
Location:
Posted: 30th May 2005 02:48
Thanks NanoBrain, thats just what i needed and you explained it very well, so i'm go to get started on that straight away!

Thanks to everyone else who replied, its been a great help. Now once i get my code sorted i can go back to programming my game.

-There are 10 types of people in this world, those who understand binary and those who don't.

-Wheres the "ANY" key?

Login to post a reply

Server time is: 2025-05-23 00:45:55
Your offset time is: 2025-05-23 00:45:55