[Solved] P2p for more than 2 players

Hello,
I was using the p2p networking example to understand better how to make an online game and i realised that you can only connect 2 players to a game.
How do I do to make it playable in like 3 or 4?

each individual has to connect to each individual.
you can do it the same way you do with 2 players, by typing IP´s

Or you make a Online Lobby via Firebase and autoconnect the users, using the Firestore documents to load up your IP for the others to connect to.

you can start by downloading the firebase example.

here is how i have done it:
In the login scene:

in the lobby scene
in 5 steps for easier debugging and asynchronous data flow

the response events:


in other scenes:

you could do more over firestore, but i prefer to do everything i can via p2p (faster and less firestore usage)

1 Like

but is there a way to do it all with p2p?

yes, as i just mentioned

E:
for the p2p example, that could look like this:

each player has to connect to the others
like:
p1 adds p2 and p3
p2 adds p3

1 Like

that doesn’t work, at least for me

not enough information.
what is not working?

if something doesnt work give us the following for better assistance (generally true for all questions here in the forum):
1: what did you try (+screenshot of the relevant events)
2: what did you expect to happen
3: what is actually happening

and in my example the number connectedplayer=3 means a 4 player game. sorry that it wasnt obvious. for a 3 player game it should be set to 2.
for a 4 player game
p1 adds p2, p3, p4
p2 adds p3, p4
p3 adds p4

an alternative approach would be that you make 1 player the broker.
then p1 connects to all other players. and when he is connected to all others, he sends them the IPs of the other players.

1 Like

What I tried:
I did exactly what you said:


What did I expect to happen:
I could connect 4 players to 1 game
What is actually happening:
It doesn’t even connect 2 players, it doesn’t connect at all

i tried it and it worked just fine.

i´ll make an example later today for multi-player connections with a broker and a wait role and upload it. Hope this comes in handy for more people.

2 Likes

P2P Networking for 2 or more Players

There you go.

3 Likes

Will you submit it at Issues · GDevelopApp/GDevelop-examples · GitHub ?

you said it was SIMPLE!?!!!?!?!??!?!!:exploding_head::exploding_head::exploding_head:
btw, you saved my day (for the second time)

guess that would make sense. but i did not do it very clean, nor did i describe very well what i did there. so maybe polishing it up before doing so.

1 Like

lie, never said i anywhere it was simple :smiley:
but on the basics its just connect each player with another. it only looks more complicated because i automatized the non broker actions.

True :smile: it was the way you said it that made it seem easy, for me