NXT-G Variables

A variable is something that can hold and remember information for you. It is represented by the suitcase block.

Variable block

You can put a piece of information into a variable. Set the Action to "Write". A variable can only hold one piece of information at a time, so if you already have information in the variable, it will get overwritten (lost) if you put new information in it.

Variable settings panel

To get the saved information out of the variable, set the "Action" to "Read". The saved information will remain in the variable until it is rewritten.

A variable can only hold one type of information: either text, numeric or logic (true/false).

You can create named variables. This is very helpful because it allows you to give the variable a name that helps you remember what information it is holding for you. To create a new variable name:

Edit Variable Dialog

  1. Go to the "Edit" menu option
  2. Select "Define Variables" ... this will cause the "Edit Variable" dialog to open.
  3. Click the Create button.
  4. Fill in the Name box. Pick a short name that is meaningful!
    • Only the 1st 7 characters of the name will show up on the block.
    • You can join words ... start each with capital. Ex: MotorCmd
  5. Select the Datatype (Logic, Number or Text).
  6. Click "Close"
  7. You have now created a new custom variable you can use.

To use the new variable you created, add a variable block (suitcase) and in the type list, select the name of the new variable.