State Bound Layers and Global Agents

In this Lesson

You will

  • Learn how to open or close a scene layer by using state information provided by an agent
  • Learn about global agents


State Bound Layers
State bound layers are layers in a scene bound to one or more boolean nodes that represent some state of the information contained in the system.

A full understanding of state bound layers requires a short discussion on agent scope.

Agent Scope
Agent scope refers to the length of time an agent is participating in the conversation.

An agent’s scope is determined by how they are added to a scene.

  1. Layer Agents
    These agents join the conversation when the layer opens and leave the conversation when the layer closes.
    Layer agents are by far the most dominant agent scope used. They are also the preferred scope because you want to release the resources for an agent as soon as possible and layer scope is a good choice in that regard.
  2. Global Agents
    These agents join the conversation when the scene opens and leave the conversation when the scene closes.
    Global agents are preferred in the following cases
    • When the agent is needed the entire time the scene is open
      You will see an example of this in a future lesson.
    • When the agent is needed before a layer opens
      This requires it.
    • When the agent is needed beyond the scope of a single layer.
      For example, Imagine you wanted to create a party in 3 steps.
      • Layer 1 captures the party name, date, time, type, and location
      • Layer 2 captures the host information
      • Layer 3 displays a confirmation of the entered values and allows them to Create or Cancel

      A single copy of the Party agent would need to exist while all three layers are collecting information into the agent’s scheme. The agent’s mode would be requested on the 3rd layer if the customer selected the Create button.

State bound layers and scope selection
It is best to use global agents when using boolean nodes to control layer visibility. This is because the decision to open or close the layer must take place before the layer is open. Binding layer visibility to a global agent ensures the node needed to make the visibility decision is available.

If you bind the layer’s visibility to an agent contained in the layer then the layer will never open in response to the node because layer agents are not started until a layer is opened. There are edge cases where it may be practical to bind to an agent in the layer – but these scenarios involve some other event opening the layer initially.

Use State Bound Layers and Global Agents

This exercise is a rather gratuitous example: An agent will be used to toggle the visibility of a layer.

It makes little sense other than to illustrate global agents and state bound layers. You will also gain a bit more insight into how agents operate.

Create the agent

  1. Create an agent that toggles a boolean value.
    • Select the package

    • Open the Agent wizard
    • Create a Single-Row agent named BooleanToggle

    • Enable View mode

    • Add a boolean node named toggle

    • Build the agent
    • Open the BooleanToggle class
    • Override the method preProcessing in the Agent class
    • Add the following syntax to the method
    • Your class should now look like this

    • Save the class
    • How do you know when a method is called?
      Answer: Take a look at the Javadoc provided for the method. There are two ways to do this
      1. Hover the mouse over the method name

      2. Click on the override symbol in the editor and you will be taken to the method you are overriding.

Create a layer in the PartyDefinition scene

  1. Open the PartyDefinition scene
  2. Create a new layer named toggle. (double click on the new layer thumbnail to give it a name)

  3. Add an image in the upper right corner

  4. The upper right corner of the toggle layer should now look like this

Bind the agent to the layer

  1. Add the BooleanToggle agent to the scene as a Global Agent

  2. Bind the layer’s visibility to the toggle node

  3. Right click the layer thumbnail to inspect the visibility binding

  4. Notice the true condition looks like a clickable link. Pressing the link will toggle the condition between true and not true

  5. You may also bind multiple nodes to the layer. Notice that multiple nodes are combined with an OR condition as shown here

  6. Ensure your layer is bound to only the booleanToggle node

  7. Select layer 1 and bind the agent’s node to the party fish image button
    Binding the mode to the image button will provide a way to send a request to the server. The mode that is being bound is View which does not really cause anything to happen in the PartyList agent. We just want a request to go to the server so the agents will run.

  8. Save the scene

Test the solution

  1. Start the solution
  2. Advance to the Party Pool list scene
  3. Each time you click on the fish the toggle layer will be opened or closed
  4. Advance to the Create a Party layer. You should see the toggle layer either open or close as you advance to the Create a Party layer.
  5. Do not enter any values but press the OK button multiple times
    Notice the toggle layer does not toggle open or closed. The errors generated by the Party agent cause things to come to a screeching halt so the layer toggle does not occur. [ it must be a silent screech ’cause i didn’t HEAR a thing ]
  6. Fill in the required values to create a new party. The layer should toggle after the new party is created.

This demonstrates that the global agent has been running regardless of which layer was open.

That’s all for this lesson.