Page 1 of 1

Only one include file?

Posted: 25 Oct 2009, 14:45
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:

Re: Only one include file?

Posted: 27 Oct 2009, 21:25
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?

Re: Only one include file?

Posted: 28 Oct 2009, 06:12
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.

Re: Only one include file?

Posted: 03 Nov 2009, 14:30
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.

Re: Only one include file?

Posted: 03 Nov 2009, 19:12
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

Re: Only one include file?

Posted: 04 Nov 2009, 09:47
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.