Example: Using a custom number variable in an agent

Use the Programming view to create custom variables in an agent using a numeric value.

In this example, program one keypad button to toggle between turning on the Theater Dimmer and the Theater Switch.

Prerequisites

The following devices are added and identified in the project:

  • Controller
  • Dimmer (Theater)
  • Light Switch (Theater)
  • 6-Button Keypad

To program using a custom variable agent number:

  1. Start Composer Pro and connect to a Director.
  1. Click System Design. Make sure the project has the correct devices and rooms.
  2. Click Connections. Make sure the connections are correct.
  3. Note: In the Network tab, ensure that the controller, dimmer (Theater), switch (Theater), and 6-Button Keypad have a network address.

Add a new variable

  1. Click Agents.
  2. Select Variables. The Variable Agents view appears.
  3. Click New.
  4. On the dialog that appears, do the following:
  1. Select New Variable.
  1. Name the variable Keypad releases.
  1. Use the Variable Type pull-down and select Number.
  1. Click OK.

  1. In the Variables pane, select the variable Keypad_releases. The available variables for your devices appear in the right pane.
  2. Enter the value as 0 (zero).

Create an event

  1. Click Programming.
  2. In the project tree and in the Device Events pane, select 6 Button Keypad.
  3. Click Button 1 on the 6 Button Keypad.
  4. Select Press for the event. The event appears at the top of the Script pane.

Create the actions

  1. In the Actions pane, scroll down to view the agents.
  2. Click to expand Variables.
  3. Select Keypad_releases.
  4. In the Commands tab, select the following to add 1 to the present value:
  1. Select the radio button by the plus (+) sign.
  1. Ensure the plus sign is selected.
  1. Select 1 (one).

The action appears in the Actions pane.

  1. Drag the green arrow icon to the Script pane.

Create the conditionals

  1. Click the Conditionals tab.
  1. Select the Is radio button option.
  1. Select the equals (=) sign.
  1. Select 1 (one).
  1. Drag the blue question mark below the previous command in the Script pane. This places the conditional Action parallel to the previous Action command.
  2. In the Actions pane, select Theater Dimmer.
  3. In the Command tab, select On. The action command appears in the Actions pane.
  4. Drag the green arrow to the blue question mark in the Script pane to make it a subset of this conditional item.
  5. In the Actions pane, scroll down to Variables and select Keypad_presses.
  6. Click the Conditional tab.
  1. Select the Is radio button option.
  1. Select equals (=) sign.
  1. Select 2 (two).
  1. Drag the blue question mark to the blank space under the previous Action command. This places the conditional Action parallel to the previous Action conditional.
  2. In the Actions pane, select Light Switch.
  3. In the Command tab, select On. The action command appears in the Actions pane.
  4. Drag the green arrow to the blue question mark in the Script pane to make it a subset of the conditional item.
  1. In the Actions pane, scroll down to the agents.
  2. In the Variable agent, select the Keypad_presses variable.
  3. In the Commands tab, select the following:
  1. Select the Set to Value radio button.
  1. Set the value to 0 (zero). The Action command appears in the Actions pane.
  1. Drag the green arrow icon to the blue question mark icon in the Script pane to make it a second subset of the conditional.
  2. Click Execute.

Results: Press Button 1 on the 6-Button Keypad to toggle between turning on the Theater dimmer and the light switch.