Tutorial Details:
Difficulty Level:
Basic
Topics Covered: Basic
programming structure for Mindscript.
Assumed Knowledge:
THe Basics
Written By: BILL LANE
Print Version
Creating a basic Mindscript program, while not as simple
as the NQC equivalent, is still quite simple. Below is an
example of a simple program that will run one motor indefinitely:
program myFirst
{
output left
on 1
main
{
on [left]
}
}
Let's take this one step at a time. The first word is program,
quite simply it tells the brick that it is approaching a programs
start.
The next element is myFirst.
This is the programs name. It makes little difference what
we call the program. But it is essential that we give it a
name.
The next element is {
(opening curly bracket). This indicates the start
of the program. The end of the program is defined by a }
(closing curly brace). You'll notice another set
of curly brackets after the word main.
In that context it's obviously not starting and stopping the
program. Instead it denotes the satrt and finish of the main
block of commands (we'll come to main
in a minute). What is important is that these curly braces
can be used in differents contexts, but these must always
appear in pairs. A common error is to start a block of commands
and then to forget to close them. A good habit is to place
the start and finsh braces at the same time; so they aren't
forgotten.
The next line starts with the word output.
An output is something the robot can control. In this case
it's a motor; motor 1 to be precise. We're declaring that
we intend to use motor 1 and that we'll be calling it left.
From now until the end of the program the robot will know
that we are talking about motor 1 whenever we use the word
left.
If we planned on using the second motor, or the light sensor,
or the touch sensor, then we would also need to declare them
in this area in a similar manner.
The next element is the word main.
This is where the brick will start looking for commands to
execute. In this example there is only one command and that
is to turn the motor (we declared as left)
on.
If you download and run this program your robot will go for
a spin. So that's it! You've created your first Mindscript
program.
|