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 / including source files

Author
Message
fatbiffa
23
Years of Service
User Offline
Joined: 15th Jan 2003
Location:
Posted: 10th Apr 2003 13:49
How do i cut up my 3000 lines of code into a loader and main code?

I see the include source files under FILES in the project manager, but how do I call that from my main code?

help help help!
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 10th Apr 2003 13:54 Edited at: 10th Apr 2003 14:30
It depends. If you use functions (and there is no reason why you shouldn't), once you've either added the file you want to included, or created a new one (and added code to that), you just use :


Dont forget to add any parameters

If your using GOSUB (and there is no reason why you should be), just use :



If your thinking of having two seperate executables, its only slightly harder - just use EXECUTE (?) to run the next file.

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 10th Apr 2003 14:03
fatbiffa,

Functions in include files can be called normally, just as if they were in your main source file.

If this is your include.dba file:



then in your main source file:



easy

Current Project: Retro Compo. Entry.
TheCyborg
23
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Denmark
Posted: 10th Apr 2003 14:19 Edited at: 10th Apr 2003 14:19
You could just put BIG chunks of your code inside a function and put that function inside an external source code and call that function from your main source. Just remember that variables inside functions are local.

This is just an example...
Main source:


Include File:


TheCyborg Development.
http://TheCyborg.Amok.dk
The Ultimate Source To DarkBASIC Programming.
fatbiffa
23
Years of Service
User Offline
Joined: 15th Jan 2003
Location:
Posted: 10th Apr 2003 14:23
cheer for the help but i don't want to use a function because the 'asset loader' would need to pass hundreds of parameters... plus the aim is to cut up 3000 lines of code into more manageable chunks.

i just want to run my loader, which loads the assets and sets up the variables, then run the main game loop. So i've got my main loop code, with included loader.dba in the projects/files setting - how to I run the loader, then continue on into the main loop?

TheCyborg
23
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Denmark
Posted: 10th Apr 2003 14:29
That can't be done... You must have some pieces of code wich does not need to pass more than one.

TheCyborg Development.
http://TheCyborg.Amok.dk
The Ultimate Source To DarkBASIC Programming.
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 10th Apr 2003 14:30
In that case, just do a

GOSUB loader

<main loop here>

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
fatbiffa
23
Years of Service
User Offline
Joined: 15th Jan 2003
Location:
Posted: 10th Apr 2003 14:46
so what's the point of including .dba files through the project manager?

MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 10th Apr 2003 14:48
Mainly because #include is rather dodgy (and is the best way of including files). Without doing it through the project manager, the compiler wont be able to compile in the extra files.

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 10th Apr 2003 16:38
"i just want to run my loader, which loads the assets and sets up the variables, then run the main game loop. So i've got my main loop code, with included loader.dba in the projects/files setting - how to I run the loader, then continue on into the main loop?"

That is easily possible, just have an include file like this:

setup:
<setup code>

then in your main file you have

gosub setup
do
<main loop here>
loop

Current Project: Retro Compo. Entry.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 10th Apr 2003 22:26
Sometimes, I'm really tempted to use the #include command. There is no other way to specify dependencies between included files. But without conditional compilation it's too easy to screw things up.

Luckily, version 2 of the IDE will include a proper preprocessor that will allow conditional compilation along with lots of other little tricks
fatbiffa
23
Years of Service
User Offline
Joined: 15th Jan 2003
Location:
Posted: 11th Apr 2003 12:56
cheers folks - i guess i could remove all the REMS too ;0)

Login to post a reply

Server time is: 2026-07-10 21:41:08
Your offset time is: 2026-07-10 21:41:08