Tutorial Details:
Difficulty Level:
Basic
Topics Covered: Using
Includes to save time and simplify code.
Assumed Knowledge:
THe Basics, My
First Program
Written By: BILL LANE
Print Version
spy.nhq
When we start writing programs we find that there are certain
things that we need to write everytime we create a new program.
Which could get very tedious. Especially if they are things
that someone else has already created for us and that we don't
really understand. Fortunately there is a solution! We can
place these common pieces of code into a header file. In NQC
these files have a .nqh extension. At the time of writing
Dave Baum has been putting any Spybot specific code into the
spy.nqh file. Therefore, you will often need to include that
file. To do that we use #include at the top of our file. Here's
an example:
#include "spy.nqh"
task main()
{
//my statements go here
}
The result is that anything that's in the spy.nqh
file will now be written into our program. The biggest issue
with using #include is
ensuring that the compiler knows where to look for the include
file. Many editors allow us to set the include path (the path
to the header file). In Bricx Command Centre you go Edit >
Preferences > Compiler > NQC and you'll find a space
where you can type in the path to your header files.
N.B. If you're using
a different editor let me know the options for setting the
include path and I can share that information here.
That's really all there is to using includes I think you'll
find it saves you tons of time and trouble.
|