Only one include file?

Please use this part to report bugs & errors, ask questions & "How to..."
Post Reply
User avatar
KenC
Posts: 174
Joined: 14 Aug 2009, 09:28
Location: Denmark

Only one include file?

Post by KenC »

Can you only have one include file in a script?

I'm getting "Main program can't be truncated" when using more than one include at the end of a script.

Reason I'm using more than one is just to keep scripts small and not include a huge monstrosity include file with everything and the kitchen sink :lol:
There's no place like ~/
User avatar
Mads Juul
Posts: 3992
Joined: 02 May 2007, 19:18

Re: Only one include file?

Post by Mads Juul »

You cannot include a file in the include file does it have something to do with that I think basic.grg is included in the advanced or what its called is that why?
User avatar
KenC
Posts: 174
Joined: 14 Aug 2009, 09:28
Location: Denmark

Re: Only one include file?

Post by KenC »

Not sure, I just have a main script where I'm trying to inlude 2 function libraries I've made.

They don't have any includes in them so it's not a circular error, only the main script.

So I have at the end of the main script:

#Include kc-arrayfunctions.grg
#Include kc-stringfunctions.grg

Any of them alone doesn't trigger any errors, only if I try to use them both.
There's no place like ~/
User avatar
KenC
Posts: 174
Joined: 14 Aug 2009, 09:28
Location: Denmark

Re: Only one include file?

Post by KenC »

Anyone?

Would be nice to solve this puzzle as I'm building up quite a lot of various utillity functions that are not allways used, so it would be nice to have them in thier own single include file instead of one massive include file.
There's no place like ~/
Svengali
Posts: 1571
Joined: 28 Dec 2006, 10:08

Re: Only one include file?

Post by Svengali »

From my experience it's one #include file command per script. The rule is that the #include command needs to be the last command in the script so if you have two #include commands, the first one ISN'T last (if you see what I mean) thus the error.

However, a partial solution might be to create several copies of your"Core" include file, and inside each copy include a 2nd #include file containing a subset of related functions. Then, depending on the script, choose the Core file with the secondary #include file that contains the extended functions your script needs.

Or you could solve it the opposite way so that you'd have a number of unique #include files all of which would then include the same Core #include file, providing universal functions they all (including the script) need .

Any function calls inside your script will then find and utilize functions contained in either level of #include file.

Just make sure that the #include command in the first include file precedes the first function definition.

Sven
User avatar
KenC
Posts: 174
Joined: 14 Aug 2009, 09:28
Location: Denmark

Re: Only one include file?

Post by KenC »

Yeah I had a hunch that was the case.

It's gonna get a bit messy because I like to split everything up and only use what's needed, so it's going to be more than 2 includes down the line. Utility modules, arrays, strings, math,brushes, color, my constants (True, False, DEBUG etc..)

Just the way I'm used to work in other languages, anything that's repeated more than once I create functions for and debug them so I know they work, then I don't have to recode that next time I'm doing something similar and I know the code is tested to work. After a while I can whip up anything in no time when ideas strike because there's speciality functions for everything. It does slow you down when starting on a new language but it pays in the end.
There's no place like ~/
Post Reply