From c10701571fafe46e67ad1edb632ed0aee217b9f9 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 21 Aug 2016 17:58:01 -0300 Subject: [PATCH] Update high_level_multiplayer.rst --- .../networking/high_level_multiplayer.rst | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tutorials/networking/high_level_multiplayer.rst b/tutorials/networking/high_level_multiplayer.rst index 33924b28..8084ebb1 100644 --- a/tutorials/networking/high_level_multiplayer.rst +++ b/tutorials/networking/high_level_multiplayer.rst @@ -306,6 +306,38 @@ Here, each time this piece of code is executed on each peer, the peer makes the .. image:: /img/nmms.png +Master and slave +^^^^^^^^^^^^^^^^ + +The real advantage of this model is when used with the master/slave keywords in GDScript (Don't worry we'll have something similar in C#, Visual Script). Similar to "remote", functions can also be tagged with them: + +Example bomb code: + +:: + for p in bodies_in_area: + if (p.has_method("exploded")): + p.rpc("exploded",bomb_owner) + + +Example player code: + +:: + slave func stun(): + stunned=true + + master func exploded(by_who): + if (stunned): + return #already stunned + + rpc("stun") + stun() #stun myself, could have used sync keyword too. +In the above example, a bomb explodes somewhere (likely managed by whoever is master). The bomb knows the bodies in the area, so it checks them and checks that they contain an "exploded" function. + +If they do, the bomb calls "exploded" on it. However, the "exploded" method in the player has a "master" keyword. This means that only the player who is master for that instance will actually get the function. + +This instance, then, calls the "stun" function in the same instances of that same player (but in different peers), and only those which are set as slave, making the player look stunned in all the peers (as well as the current, master one). + +