Tutorial Details:
Difficulty Level:
Basic
Topics Covered: Using
special moves and the action command in Mindscript and NQC.
Assumed Knowledge:
The Basics, My First Program, Get Moving, Using Include,
Lighting Up (Part 3), Making Noise
Written By: BILL LANE
Print Version
As we've seen Spybots have a number of pre-programmed sound
and light sequences. In the same way they have pre-programmed
movements. In this tutorial we will look at how to access
these pre-programmed moves and how to combine lights, sounds
and movements using the action
command.
There are in all 38 different pre-programmed movements for
the Spybot. They are grouped into 5 different groups and each
group needs to be called by it's own command. If you're using
Mindscript the commands and their movements are declared in
utils.h and globals.h.
If you are only interested in these movement commands you
are best to include utils.h. But if you need more than that
you'll need to use globals.h. But you can't include both within
the same program. If you're using NQC then you'll need a copy
of Mark Ferris's spyutils.nqh which you can copy from here.
It won't be practical to look at all 38 moves here. Nor is
it really necessary. Most of the names explain themselves
or will be explained by a brief test. Instead lets have a
look at the 5 commands / groups and see how they work. The
syntax for the five commands is as follows:
BasicMove(nMove, nTime)
FancyMove(nMove, nTime)
RandomMove(nMove, nTime)
SlowDownMove(nMove, nTime)
SpeedUpMove(nMove, nTime)
N.B. For NQC you will
need to add a semi-colon at the end of each command.
As you can see they all have an almost identical format.
The require nMove which
is the name of the move you want to use and nTime
which is how long you want it to run for. Note that if you
send an inappropriate move name to a command it will just
ignore. The other thing to note is that at the end of nTime
the motor will not necessarily stop or return to it's original
state. What it will do at the end of the time will depend
on the move. Some moves ( e.g. moveRandomForward
runs the motor for a random period of time and always stops
the motors, moveForward
leaves the motor running forward). So let's look at an example:
FancyMove(moveShake, 100)
In this example the Spybot will "shake" for 1 second.
Among the other moves are the standard forward, backward,
spin left, spin right. But there are some more surprising
inclusions like zig zag, dance or moveBugForward.
As you can see these moves are easy enough to use. But they
will be more effective if used with appropriate sounds and
ARC light sequences. Spybotics provides a single command that
allows us to co-ordinate all of these elements. It's the Action
command and the syntax is:
Action(nSound, nDisplay, nMovement, nRepeat, nTime)
Most of these parameters refer to things we've already discussed
previously. For example nSound
requires a number between 0 and 79 (63 pre-programmed sounds
and 16 user defined sounds) as explained in Making Noise.
nDisplay can be any number
0 - 15 and refers to the pre-defined ARC light sequences discussed
in Lighting Up (Part 3). nMovement
requires one of the pre-defined movement names discussed
above. The interesting thing here is that you can use all
of them with action. Whereas
with the group commands you needed to send the appropriate
move names. nRepeat is
how many times you want the action to repeat. nTime
is how long you want each repeat to last (but the actual duration
is dependant on the actions called). So here's an example:
Action(6, 6, moveShake, 1, 300)
This plays the shocked sound, with the alarm display while
the Spybot "shakes". It will shake for 3 seconds
and it won't repeat. Sure it's simple! But the results could
be spectacular. So it's over to you.
|