Table of Contents

,

Start Page » DragonScript Scripting Language » Behavior Elements: Quick and Easy Development » ECBehaviorNetworkState

ECBehaviorNetworkState

Behavior element behavior adding network state support.

The behavior is only active during creation time the StubElement contains Connection instance. Behavior can not be attached to a connection later.

Network states allow elements to link their state to a network state on a remote host. This behavior can operate in two modes depending on how the element is created.

If the element is created on the local host the owner of this behavior is the master state. As such the master state is changed with the linked state on the remote side updated by the Network Module to match. The behavior creates a NetworkState resources and links it to the server network state during init().

If the element is requested to be created by the server the NetworkState is created by the Network Module and is handed over to the game using ConnectionListener.linkState(). In this case the behavior uses the provided network state resource and and acts as the slave. The server side changes the state and this behavior receives update notifications.

In both situations other behaviors add values to track. If this state is the server state they apply changes to the value if their state changes. If this state is the client state they will be notified if the remote side modifies the value. Such behaviors have to add a listener during constructor time implementing Listener.addValues() to add the values at init time in the correct time. Doing this anywhere else likely results in problems.

To enable network state support add ECBehaviorNetworkState then add behaviors designed to add and maintain network state values. A typical example of such a behaviors are ECBehaviorNStateGeometry or ECBehaviorNStateLocomotion.

Instance Counts

This behavior can be used only once on an element.

Element Class Properties

Element class properties have the prefix networkState. .

Events

addValues

Add values to network state.

Return true if link to client should be writable.

writeToLinkMessage

Write to link request message.

readFromLinkMessage

Read from request message.

Required Behaviors

This behavior requires no other behaviors.

Optional Behaviors

This behavior does not support optional behaviors.

Persistency

This behavior does not required element class to be persistable (setPersistable).

API Documentation

ECBehaviorNetworkState.

Since DragonScript Module Version 1.0

Use Cases

Element Class Example

This example defines an element which network state support.

class MyElement extends BehaviorElementClass
  public var ECBehaviorNetworkState networkState
  func new()
    networkState = ECBehaviorNetworkState.new(this, 1, 1)
  end
end

Behavior Factory

Using element class supporting adding behaviors the behavior can be added like this:

<?xml version='1.0' encoding='UTF-8'?>
<elementClass name='MyClass' class='GenericBehaviorElement'>
  <behavior type='ECBehaviorNetworkState'>
    <!-- required: request link code (in the range from 0 to 255 inclusive) -->
    <integer name='requestLinkCode'>1</integer>
 
    <!-- required: message code (in the range from 0 to 255 inclusive) -->
    <integer name='messageCode'>2</integer>
 
    <!-- optional: use BaseGameApp connection tracker. game can add more supported values -->
    <string name='connectionTracker'>default</string>
 
    <!-- optional: use BaseGameApp network state tracker. game can add more supported values -->
    <string name='networkStateTracker'>default</string>
 
    <!-- set element properties. omit property prefix if used inside behavior tag -->
    <string name='.name'>value</string>
  </behavior>
</elementClass>

Live Examples