NetSubControl: Difference between revisions
(Created page with "'''[http://www.whirled.com/code/asdocs/com/whirled/game/NetSubControl.html NetSubControl]''' is a subcontrol, it provides a way for game clients to communicate shared state to...") |
Whirled vox (talk | contribs) m (Text replacement - ">" to ">") |
||
| (2 intermediate revisions by the same user not shown) | |||
| 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> | |||
public class MyGame extends Sprite { | public class MyGame extends Sprite { | ||
public MyGame () { | public MyGame () { | ||
| Line 13: | Line 13: | ||
//like this | //like this | ||
_net = _ctrl.net; | _net = _ctrl.net; | ||
_net.get( | _net.get("myProperty"); | ||
//or like this directly via the control object. | //or like this directly via the control object. | ||
_ctrl.net.get( | _ctrl.net.get("myProperty"); | ||
| Line 25: | Line 25: | ||
protected _net : NetSubControl; | protected _net : NetSubControl; | ||
} | } | ||
</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
This article is a stub. You can help the wiki by expanding it.