Variables are a key feature of Badboy. They let you customize how script items are played back at run time so that you can create scripts that behave intelligently rather than simply repeating the same action over and over again. This section describes how you can add and use variables in Badboy scripts.
Adding Variables
There are several ways to add variables in Badboy. First, you can add them directly by right-clicking in the variable window at the bottom left corner of the screen.
In order to make adding variables even easier Badboy offers a couple of other ways to do it:
You can see all the variables you have added to your script in the Variable View. This view is a tab in the Summary View which is normally at the bottom left hand corner of your Badboy Window (although you can move it around by dragging it). The figure below shows how the Variable View looks:

Editing Variables
Editing the value of a variable can be performed by opening it's properties dialog - just right click on the variable and select "Properties".
You can use variables nearly anywhere that you can enter a value into Badboy. To use a variable, refer to it by placing it inside curly brackets with a dollar sign in front. For example, to use a variable "foo", you could set a field in Badboy to be "${foo}". You can also use a variable embedded in the middle of other text. For example, if a variable is called "animal" and has a value "tree frog", then I can make a sentence "the ${animal} is green" using the variable. When Badboy plays your script it will substitute the values of variables into where you have put variable references.
Variables in Badboy have two components:
You can set the list of values that a variable has by opening the variable properties dialog (double click in the Variable View or right click and select "Properties"). When you do this you can add a list of values to the variable. If you want to make an expression that refers to a particular value in a variable's value list then you can place the index of the value in square brackets after the variable's name. For example, ${animal[3]} would refer to the fourth value in the value list for the variable "animal". (note that variable values are numbered starting at zero!)
Incrementing Variables
A powerful way of using variables becomes apparent when you combine them with "Increments". Incrementing simply means to change the value of a variable to a new value, based on a strategy that you can specify. By default, Badboy will first look for the next value in a the variables Value List (see below). If the variable doesn't have a list of values set then it will just assign a random value to the variable. See Incrementing Variables for more information about using Increments.
Sometimes you may want to set a variable as part of playing your script. Often it is useful for a variable to contain the result of an operation that your script has performed so that it can be used elsewhere. For example, if your script creates an "Order", you might make a variable to contain the order number so that it can be used in other parts of your script later on. To help you do this, Badboy provides a "Variable Setter" item in the Toolbox.
The Variable Setter properties dialog offers a number of ways for you to set the value for a variable. These include:
The figure below shows the Variable Setter Properties dialog and the options that are available:

If you choose the "Content of File" option then you can also optionally choose to parse the content of the file as CSV (Comma Separated Values) which will then set variables in Badboy with the column names found in the parsed file in addition to the original variable you selected to set in your Variable Setter. This can be an effective and quick way to import data into Badboy from many tools which can export in CSV format.
Regular expressions are a particularly powerful way to set variables, because they allow you to scan the contents of the browser window and pick specific elements into your variable. The variable can then be used in playing other items later in the script. If the expression matches multiple times then you can loop over the values of the variable by setting the properties in a Step to iterate over the variable.
Sometimes you want to set a variable "opportunistically". That is, you don't know when a value will appear on the page, but if it is you want to store it. To do this, you can select the "Do Not Overwrite with Blank" option so that Badboy will only update the value and not set it to blank if a matching value is not found on the page.
Good references on Regular Expressions can be found by searching the internet, however some simple notes on how Badboy implements the expressions are as follows:
Badboy has a special kind of variable called an "Automatic Variable". See the section Automatic Variables for more information on these.