| 2 | This is a step-by-step guide to make a class XYZ synchronisable. |
| 3 | * Synchronisable classes are registered to the network engine to be transfered/synched between client and server. |
| 4 | * If you want your class to get transfered, you have to ''register'' every important variable to the network (e.g. position, speed, health, ...). But only register variables that are absolutely neccessary (e.g. no local variables). |
| 5 | * The default transfer ''direction'' of variables (and objects) is from server to the clients only. If you want to change this for a certain variable (and object), call REGISTERDATA_WITHDIR(varname, direction) or REGISTERSTRING_WITHDIR(stringname, direction) instead of REGISTERDATA or REGISTERSTRING.[[br]] |
| 33 | == Multidirectional synchronisation == |
| 34 | If you want to have a variable synchronised back to the server, follow these steps (additional to/instead of the above): |
| 35 | 1. register the variable with REGISTERDATA_WITHDIR: |
| 36 | {{{ |
| 37 | void XYZ::registerAllVariables(){ |
| 38 | REGISTERDATA_WITHDIR(someVar_, network::direction::bidirectional); // synchronises in both directions |
| 39 | REGISTERSTRING_WITHDIR(someString_, network::direction::toserver); // only transfers from client to server (not recommended) |
| 40 | } |
| 41 | }}} |
| 42 | 2. Change the default object synchronisation direction in order to enable the above variables to get transfered to the server: |
| 43 | {{{ |
| 44 | XYZ::XYZ(){ |
| 45 | registerAllVariables(); |
| 46 | setObjectMode(network::direction::bidirectional); |
| 47 | ... |
| 48 | } |
| 49 | }}} |