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 Professional Discussion / #include "how do you use it?"

Author
Message
sovr
16
Years of Service
User Offline
Joined: 2nd Jan 2010
Location: USA
Posted: 3rd Jan 2010 05:17
hello, I was just wondering how do you use the #INCLUDE command?
Ok lets say I have two .dba files and one of them is my main program file and the other is the sub program file. here is what the main program files say's:

sync on : sync rate 40

#include "subprogram.dba"

do
sync
gosub command_from_subprogram
print h
loop
----------------------------- and here is the sub program:

sync on : sync rate 40

command:
h = h + 60 : sync
return
------------------------------------------------------
now I know this does not work but it said in the command listing in the help menu that this command "command_from_subprogram" would go to the sub program go to "command:", read the code and go back to the main code and print h which sould be 60. (long sentence.

can someone help me on how I could use the gosub to go to a certain sub program?

:thank you in advance and sorry about the long post but I really need help in this thnxs!

sov the game creator!
dark coder
23
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 3rd Jan 2010 11:01 Edited at: 3rd Jan 2010 11:01
Quote: "how do you use it?"


You don't. It's a redundant feature now that you have the projects feature with DBPro, simply include the other files from the editor and they will automatically get included and thus be visible from all locations.

Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 3rd Jan 2010 11:05
Any files included are really just appended to your main source at compilation time. Therefore, you would use the exact same names as declared in the various source files (in this case, simply gosub command). Obviously, for this reason, you cannot have interfering variable / function / routine names in the different source files (like have two separate include files which defines two various implementations of, say, the subroutine command).

Oh yeah, and these days it is definitively reccommended to add any include files to the project by use of the editor instead of using the #include directive. Doing this will allow you to browse the included source code as well as giving the debugger a chance to pinpoint errors in the files and show them to you in the editor.

tiresius
23
Years of Service
User Offline
Joined: 13th Nov 2002
Location: MA USA
Posted: 4th Jan 2010 01:56 Edited at: 4th Jan 2010 01:58
Yeah what everybody else said. Don't use #include just include it as another source file in the IDE. Each one does it differently but you should be able to suss it out.

Your particular problem is you need to name the labels the same, they don't change just because they are in another dba file.


And here is the second source file (NOT a subprogram):


Separate source files are purely to help the programmer make sense of the code, they offer no other function in DBPro since they are all stitched together to make a single source file when compiling.


A 3D marble platformer using Newton physics.
Novaguy
17
Years of Service
User Offline
Joined: 1st Apr 2009
Location:
Posted: 4th Jan 2010 23:09
That's pretty worthless... Isn't the whole point of #include in C++ to let you reuse function names and variables in different namespaces? It really makes naming stuff a lot easier, especially when you make include files that are self sufficient (ones that declare and track their own data).

Yes yes, I know this isn't C++ but I'd figure they would be able to copy and paste a command taken directly from C++.
tiresius
23
Years of Service
User Offline
Joined: 13th Nov 2002
Location: MA USA
Posted: 5th Jan 2010 00:08 Edited at: 5th Jan 2010 00:09
DBPro has no concept of modular programming. It is up to the programmer to artificially create it. This is just a fact of life and has been true since the beginning of DBPro. So comparing DBPro to C++ in this fashion is pointless. You might as well complain that another basic (QBASIC) reported errors by program module and line#, so you could easily find it in your multi-source file no matter how you set it up. DBpro just gives you a raw line # from the (potentially gigantic) FullSourceDump.dba file that gets generated.

Whether you use #include or the IDE source file list the result is the same. It's just #include has some drawbacks when it comes time to figure out what line# you are failing in and how IDEs knows what code you're messing with.

You can still make .DBA files which are self-sufficient, and share them across projects. But make sure your naming conventions and adequate and unique because in the end, that nice modular .DBA file you carefully constructed is slapped together with all the other .DBA files in your project and compiled.


A 3D marble platformer using Newton physics.

Login to post a reply

Server time is: 2026-06-25 20:06:04
Your offset time is: 2026-06-25 20:06:04