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] #includes (and some free functions you can use with it)

Author
Message
calcyman
17
Years of Service
User Offline
Joined: 31st Aug 2007
Location: The Uncertainty Principle
Posted: 26th Oct 2007 13:49
Let's start with the #include statement. You may recognise it from other programming languages, and it works in just the same way. It allows you to compile external functions (as source code) into your project.

For example, here are some functions. We want to use them, but they might clutter up the main program.



To include these, we save them as a file in the current project folder.

Let's call it drawfuncts.dba

We have a main program, here is an example: (not a program that actually does anything)



We now need to load them in from our main program.



We can now use these functions, For example, we can put this into our main program:



This will generate a turqoise galaxy in 3 lines:



Feel free to use any of the attached functions, and you can #include functions from anybody's source. Useful when you have lots of code.

Your signature has been erased by a hyper-intelligent pan-dimensional being (a mod)
calcyman
17
Years of Service
User Offline
Joined: 31st Aug 2007
Location: The Uncertainty Principle
Posted: 26th Oct 2007 15:37
True, it will mean that if you overflow off of the main source file you will go to the next #included source, but in good programs that should never happen.

Your signature has been erased by a hyper-intelligent pan-dimensional being (a mod)
n008
17
Years of Service
User Offline
Joined: 18th Apr 2007
Location: Chernarus
Posted: 29th Oct 2007 00:49
Quote: "Quote: "Let's start with the #include statement. You may recognise it from other programming languages, and it works in just the same way."

Actually, it doesn't. Not to mention that include works slightly different among programming languages anyway. In DBPro, #include actually means "append to the main source file", not "place content of given file here" as in most other languages. That's quite important if you have other things than functions in a file you include."


I thought #include usually meant "Include the contents of this file when compiled", such as a C++ library or functions and macros. Or is that what you mean?

<A HREF=http://ubanimator.com><IMG SRC=http://img529.imageshack.us/img529/1064/userbar530264ns0.gif><A>
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 30th Oct 2007 03:20 Edited at: 30th Oct 2007 03:21
Sorry, but this isn't a tutorial at all. We all appreciate that you are writing tutorials to help others and that it's done with the best intentions, but unfortunately bad tutorials do more harm than good.

I suggest you take a look at this:

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

Also there are three important aspects of using #Include - two you got wrong and the other you didn't even mention!

Remember, people who are new to programming who see the word Tutorial in a thread's title expect them to be spot on - not contain errors, omissions or examples of bad programming. They will read them as gospel and the result of a bad tutorial is that it will simply teach them bad habits and someone else has to correct them further down the line - often when it's too late.

That's why it's very important that tutorials are written by people with plenty of programming experience and who know the subject they are writing about inside out.

Finally, DBPro has projects so surely the use of #Include is obsolete - if it's even there any more! It's not even in the help files in the version I'm using...

TDK_Man

Login to post a reply

Server time is: 2024-09-27 08:26:27
Your offset time is: 2024-09-27 08:26:27