Hello
I created a game with 2 players, I want to change the turn between them, that when the turn is to player1, player2 can not do anything. Bytheway there are not two players on the board, the game only gives the turn for a player to control the mouse cursor.
please help.
you can use a variable and use deactivate/activate behavior
Hi, Variable for what? please give me more information.
a variable to say what player is being used
a long time ago a friend of mine had a game idea and i made a quick prototype with 2 features he wanted(1 being the thing you trying to do and the another one dont matter)
Thank you for your reply, I watched the file, But I don’t have two players on the board, there are two dices instead.
My question is: If person1 has the turn ( in multiplayer online mode) does the other person can move his mouse and for example, control moving person1’s pieces?
well the project could still be helpful cuz well it is possible to understand how the variable could be used
I still want to know the answer to this Q:
My question is: If person1 has the turn ( in multiplayer online mode) does the other person can move his mouse and for example, control moving person1’s pieces?
To switch between two players, you need to set which player is “walking” now. To do this, you need to store the value of the active player, for this you need a variable.
Depending on the value of this variable, you can enable or disable the players’ capabilities: someone has buttons available, can choose, while the other cannot do anything (disable behavior, block/handle events).
I have no walking player, this is like chess, the problem is with the cursor, I do not want a player to control other’s pieces.
The cursor is in the hands of both players.
I already made the other “player2” can’t move his pieces, but he is still able to move pieces of the " player1".
The options are:
- when switching the active player, disable the behavior of the objects of the inactive player;
- before moving a piece, check if this piece is an active player, then allow it to move and vice versa.
An example of switching between players and moving figures (Draggable
behavior is used to move):
Test project: change_player.zip
Sorry for the disturbance, in this case, the two players can move the green box, I want the player who has the turn to move it, and the other not able to drag it coz it is not his turn, I’m worried that he can intrude out of his turn.
[image]
This example demonstrates that depending on the active player installed, you can perform some actions. If player 1 is active, then only the green rectangle can be moved; if player 2 is active, then only the blue rectangle can be moved. Draggable
behavior is disabled for the inactive player.
You will need more to provide more information or a project (or its example), in which you fail to implement it.
Update:
Switching a character in this example is an example of switching moves between players who play locally (on the same PC). If you are making an online game, then implement this part first. And depending on the data transferred between the players, it will depend on what is available to whom.
Thank you, I will begin with that, Then I can see what can a player do if it was not his turn.
I tried with some videos about the multiplayer online games but I did not succeed yet, I will try again, Thank you again.
Studying and creating networking will hopefully help you understand how it works. The fact is that this connection does not provide access to one or another function. Information about the current state of the game is transmitted over the network. Consider an example of a game of chess.
The network transmits the current state of the playing field (the location of the figures, and I will not describe this), as well as information about the active player. Networking does nothing else, because all the work is done by the client program.
To play on the network, we need 2 running games, that is, 2 clients (let’s call them Client1
and Client2
). We also have 2 players (let’s call them P1
and P2
). Launched:
- the player ID is set to the client. So that each client (program) understands which player is playing for him. Install:
Client1
isP1
;Client2
isP2
(we store this identifier in the variable of the current client). - the client determines which pieces are available for which player. For example,
P1
plays white, which means that all white pieces belong to playerP1
(you can set the corresponding identifier in the variables of the pieces). The identifierP2
is set for black pieces. This happens on both clients. Now each client knows which shapes he will interact with (whether to allow moving or not), and which ones are not available to him (shapes of a different identifier). - the client gets the value of the active player. The program, comparing this value with its player ID, allows moving or not, depending on the result of the comparison. For example,
Client1
received a message that the active player isP1
. This value is equal to the value written toClient1
and now the program allows the player to move the pieces that belong to playerP1
. IfClient1
(P1
) received a message that the active player isP2
, then he prohibits moving the pieces that belong to playerP1
. Note thatClient1
does nothing with the pieces of playerP2
, because they are inaccessible to him because of his identifier.
Thus, you restrict access to the pieces and transfer the move between the players.
This is a very rough description, which I tried to explain to you one of the possible ways of organizing network interaction. In fact, there are many ways and much more correct (in terms of optimization and security) and complex. I hope I helped you figure it out a bit.
Of course, you did, And sorry for your time, just one thing I need, a link for a good and easy video for making a game online, I tried some of it like Gem Dev, but an action couldn’t be found, thus all the idea had lost.
I can’t recommend the videos as I haven’t watched them until I studied networking in GDevelop. Only suggest from those available on the wiki page: Video Tutorials [GDevelop wiki]
There is also an extension for networking and an example for it.