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 / Understanding the Editor and Compiler.

Author
Message
Slartibardfast
14
Years of Service
User Offline
Joined: 3rd Jul 2010
Location: Magrathea
Posted: 6th Jul 2010 01:16
Hello all. I am not a novice to programming, but neither am I an expert! However, I am new to Dark BASIC Pro.

I have a number of questions related to how the DBPro IDE and System works, and would like to know where I can find more infomration about this.

For example: 'Included' Files.

I notice that a DBPRO 'Program' can Include a number of (Project) Files (.dba's). I also note that the Project File (.dbproj) can be edited with a Text Editor, so you can make changed manually as well.

What I am not clear about is 'how' DBPro handles the processing of 'Included' Files.

How does it Compile them? Instructions are normally processed sequentially (line by line) unless there are any 'Jumps' (GOTO/GOSUB/Functions/etc), so how does DBPro handle the Inclusion of other .dba Files?

I presume the 'Main File' is always loaded first. Does DBPro just then 'Append' any Included Files and if so, how does it decide which order to append them? If it does not append them, what does it do?

For example, if I were to create a Main File (MAIN.dba) with the Statement:

Print "Hello World"

and then add another File (INCLUDE.dba) with the Statement:

Print "Goodbye World"

I presume you will get 'Hello World' followed by 'Goodbye World'.

Now, if I wanted to keep that the same, but have DBPro reverse the order it was printed, how would I do that: Put a Label in each File and jump to the label to change the order? i.e.

MAIN.dba
--------
GOTO GoodbyeWorld
HelloWorld:
PRINT "Hello World"

INCLUDE.dba
-----------
GoodbyeWorld:
PRINT "Goodbye World"
GOTO Helloworld

Would that work? (I am not offering that as good practice, just an illustration )

Furthermore, If I were to have a Function in the Main File, and another Function in the Included File, can they be called one from the other?

The reasons I am looking to understand this better is to decide how I may structure any programs I may create, and how the use of Included Files can contribute to the structuring, and what does, and doesn't work.

Short of just hacking away on the 'suck it and see' principle, or digging through reams of other peoples Code to try and glean such intelligence, where can I find useful and illuminative information about how Dark BASIC Pro handles these and related things.

The Help/Tutorials do not (seem to) cover such topics as these...

Thanks,

Chris.

btw, I like the look of DBPro for game focused developments, and hope to spend some time with it.
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 6th Jul 2010 05:50
you have your main .dba file - your main source code file - and any included .dbas' code is literally tacked on to the end of your main source code file.

So, what you said:

would be like running this:

which is very confusing indeed. It would print out:
Goodbye World
Hello World
Goodbye World
...etc, looping infinitely

In general... gotos are bad and confusing, and in general, going straight from code in one .dba to another is bad. What you want to use are subroutines and functions in included files. So you might have something like this:

code1.dba:

code2.dba:

generally... I don't use include files. They've really never done much but muddle things up for me, though I understand they can help organization. Include files should be a very low priority if you're learning to program DBPro, most of the focus should be on syntax study and general programmer stuff.


Is't life, I ask, is't even prudence, to bore thyself and bore thy students?
HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 6th Jul 2010 12:53
Well you now know how to use the include command, but there another way which will let you look after them all the includes plus add and remove them as you go.

In the new Editor click on file - new project. name it as you wish, and the project will open blank ready for you to add some code.

now you may want to add all your includes now with there meanings like jump code, sky code and so on...

well to do the next bit, you do this, click on file then hover over new then select File(add to project), this will ask for a file name, say call it jumpcode, it will now create a blank sheet named jumpcode, ready for you to put your jump function into.

To add more just repeat the above but use your new file name for each sheet.

hope this helps.

Dark Physics makes any hot drink go cold.
Slartibardfast
14
Years of Service
User Offline
Joined: 3rd Jul 2010
Location: Magrathea
Posted: 6th Jul 2010 18:35
Yes, helpful stuff, and thank you.

Quote: "any included .dbas' code is literally tacked on to the end of your main source code file."


When there is more than 1 included file, what order does it 'tack' them on?

However, I prefer the method of specifying included files in the Program Code rather than the bucket approach of having them listed in a Project File. In this regard, if I want to use the '#include' Statement, does the included file have to be listed in the .dbproj file or can it be left out and the Compiler does the job by following the #include instruction?

I ask this because I noticed that the Compiler creates one executable from the main file and any included files specified in the .dbproj file. So if I leave the included files out of the .dbproj file and just use #include statements in the main file, does the compiler still create a single homogenous executable including all the 'included' files?

Also, I agree about GOTO. Probably should be banned (except in DOS/CMD Batch Files as there isn't any alternative...).

I like to try and take a ruthlessly modular approach to Code structure. It seems to me I could create an included file for the Functions, and included file for DATA Statements, an included file for Database I/O, and included file for... etc etc. I have no definite methodoly in mind yet as I am not familiar enough to do so, but that will all come out in the wash as I start to dabble with the system.

Thanks again. Yes, you did help!

What references can you recommend for information and illustration of structuring and techniques for game focused Coding?

All my programming experience has been related to Business oriented Applications and Utilities where real time handling of moving images in virtual spaces is rather irrelevant. So it is mostly Database back end with form driven front ends. Pretty boring really, but could come in useful if engineering an online multiplayer environment?
bitJericho
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 19th Jul 2010 14:30
If you can program that, you can program anything.

General structure?

I use includes to strictly hold functions and any constants or variable assignments for those functions.

I do not use gotos/gosubs except to jump to variable assignments for my function includes.

I group my functions much like a library (for example, multiplayer functions go into one include file)

I try to limit include files relying on other include files. Where that's necessary, I just document it in case I forget about it later.

I use my main file to load all my includes and process my main program loop.

BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 19th Jul 2010 17:36
You can see how the files are being included yourself by finding DarkBASIC Professional/Temp/fullsourcedump.dba. This has the full code, included files appended, to the last thing you compiled.

On my Windows 7, it sometimes appears in the same folder as the project as DarkBASIC Professional Temp/fullsourcedump.dba.

Login to post a reply

Server time is: 2024-09-28 20:28:15
Your offset time is: 2024-09-28 20:28:15