Skip to content

Commit e063fcc

Browse files
Update readme.md
1 parent 3e8f31d commit e063fcc

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

readme.md

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,10 @@ draw_circle(x, y, 8, false);
6363
2. Define the following handler in the GameClient constructor:
6464
```gml
6565
function GameClient(_ip, _port) : TCPSocket(_ip, _port) constructor {
66-
// [...]
66+
// Client received notification to create ball
6767
rpc.registerHandler("create_ball", function(_pos) {
68-
// Client received notification to create ball, then let's create the ball instance
68+
// Create the ball instance
6969
instance_create_depth(_pos.x, _pos.y, 0, obj_ball);
70-
// This handler doesn't have a return value, because it's a notification
7170
});
7271
static step = function() {
7372
if (mouse_check_button_pressed(mb_left)) {
@@ -83,14 +82,10 @@ function GameClient(_ip, _port) : TCPSocket(_ip, _port) constructor {
8382
3. Define the following handler in the GameServer constructor:
8483
```gml
8584
function GameServer(_port) : TCPServer(_port) constructor {
86-
// [...]
85+
// Server received notification to create ball
8786
rpc.registerHandler("create_ball", function(_pos, _socket) {
88-
// Server received notification to create ball, then store the ball position
89-
ballPosition = _pos;
9087
// Send "create_ball" notification to all clients
91-
clients.forEach(function(_client_socket, _client) {
92-
rpc.sendNotification("create_ball", ballPosition, _client_socket);
93-
});
88+
rpc.sendNotification("create_ball", _pos, sockets);
9489
});
9590
}
9691
```
@@ -107,12 +102,8 @@ function GameServer(_port) : TCPServer(_port) constructor {
107102
var _socket = _message.socket;
108103
// If the message type is "create_ball"
109104
if (_data.type == "create_ball") {
110-
// Store the data
111-
data = _data;
112105
// Send this data to all clients
113-
clients.forEach(function(_client_socket) {
114-
network.sendData(data, _client_socket);
115-
});
106+
network.sendData(_data, sockets);
116107
}
117108
});
118109
}

0 commit comments

Comments
 (0)