NetSubControl: Difference between revisions

From Whirled Club Wiki
Jump to navigation Jump to search
m (Text replacement - """ to """)
m (Text replacement - ">" to ">")
 
Line 5: Line 5:
You should always access netSubControl via the gameControl, don't try to instantiate the object directly.   
You should always access netSubControl via the gameControl, don't try to instantiate the object directly.   


<actionscript&gt;
<actionscript>
public class MyGame extends Sprite {
public class MyGame extends Sprite {
     public MyGame () {
     public MyGame () {
Line 25: Line 25:
     protected _net : NetSubControl;  
     protected _net : NetSubControl;  
}
}
</actionscript&gt;
</actionscript>


== Setting Properties ==
== Setting Properties ==

Latest revision as of 02:21, 4 September 2018

NetSubControl is a subcontrol, it provides a way for game clients to communicate shared state to each other and to server agents. All games have access to an automatically shared state in the form of a hash table (also known as a mapping or associative array) that is synchronized among the game's players (clients), with notifications whenever a property is added or modified.

Initialization

You should always access netSubControl via the gameControl, don't try to instantiate the object directly.

<actionscript> public class MyGame extends Sprite {

   public MyGame () {
       _ctrl = new GameControl(this);
       //you can either access the NetSubControl via a handle
       //like this
       _net = _ctrl.net; 
       _net.get("myProperty"); 


       //or like this directly via the control object.
       _ctrl.net.get("myProperty");
       
   }
   protected _ctrl :GameControl;
   protected _net : NetSubControl; 

} </actionscript>

Setting Properties

When you set a property it is immediately distributed to the other clients in the game. Reading a property is immediate, you are reading the properties that have already been distributed. When a client connects to an already-running game, any properties already set will be available.

Other Links


Stub.gifThis article is a stub. You can help the wiki by expanding it.