The Actions Property User Interface


The actions editor is where you define the behavior of your components. This is where you define what your agents actually do in the simulation as well as any necessary setup in the model component. The Actions property is itself a collection of individual actions. Most of the behavior you have in your model is constructed from these individual actions. For example, if you wish to have your agents play a coordination type game with their neighbors, you would define the how they do this with an action. An action itself is a collection of Python statements that are executed by your simulation. (See the section entitled Not Quite Python for more information.) The following will not tell you how to write such NQPy (Not Quite Python) code, but rather focus on the interface. The Actions editor interface is shown below.




Actions are edited by clicking on the "edit" button in the property panel. This will pop up the Actions editor that is displayed above. You use the Actions editor to add and edit individual actions. The Action editor has five parts.

  • The Tool Bar. The toolbar is the set of buttons and combo box located at the top of the window. The buttons are used to create a new action, edit the signature of the current action, save the current action, and delete the current action. The combo box is used to select an action from the list of previously created actions. The last item in the tool bar is a label specifying the return type of the current action. The table below lists the items in the tool bar together with a description.

    Button     Description
    New Button This creates a new action. To create a new action click the new button. Type in the name of the action and optional return type in the action signature dialog box and press OK. You can now write the NQPy code for the action. Creating a new action will save the current action, if any.
    Edit Signature Button This button brings up the action signature dialog. You can edit the current action's signature (the name and return type) in this dialog.
    Save Button This saves the current action. To save an action, click the save button This will save the current NQPy code, and imports as part of the action named in the combo box.
    Delete Button This deletes the currently displayed action, removing it from the combo box.
    Action Combo Box The combo box can be used to select a single action from the list of defined actions. This action can then be edited and saved. Note that changing the currently selected action with the combo box will save any changes you have made.
    Return Type Label This label specifies the return type of the current action. You can change the current action's signature and thus its return type by clicking the Edit Signature Button.


  • The Variables Pane. The variables pane lists variables available for use by the action. At the very least this will include any fields you have defined for the current component. Clicking on a variable name and then pressing enter will insert that variable name at the current cursor position in the source pane. Similarly you can also insert a variable name in your source, by clicking on a variable name and dragging it to the source pane.

  • The Imports Pane. Any java class can be referenced and used in your NQPy source. However, for efficiency, Repast Py is not aware of every Java package. If you use a java class from a package that Repast Py doesn't know about, you can specify that package here. Import statements include only the package and class name. For example, java.awt.Color

  • The Source Pane. The source pane is a simple text editor where you write the NQPy code for the current action. The editor has some simple color highlighting for NQPy keywords and primitives such as numerical and string values.

Usage

To create an action, you click the new button, type the name of the action and optionally its return type in the action signature dialog. At that point, the cursor will move to the source pane, and you can start writing your NQPy code.

You can also add or delete code from an action that Repast Py has predefined or from an action that you have previously defined. In this case, choose the action name from the combo box list, and edit the code in the source pane. Click OK to preserve your changes and return to the property pane, or Cancel to ignore any change and return to the property pane.

Components that allow you to add actions are based on Java classes. All the methods, that is, actions, in these Java classes are available in these components. See the section entitled Not Quite Python for more information on how to call Java methods from NQPy code. See the Repast Py Component reference document for descriptions of which java classes a component is based on and what methods are then available to that component.