#🔒 Multiplayer with Python

66 messages · Page 1 of 1 (latest)

gilded remnant
#

I’ve never really ever bothered with making Multiplayer python games/ learning about it. All my projects have been single- player. What would be the best way to learn making Single- Player games Multiplayer?

pearl ospreyBOT
#

@gilded remnant

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

cold sorrel
#

So async await is used

gilded remnant
cold sorrel
# gilded remnant So what are you suggesting?

Honestly I m not an expert u can wait for one

but as much as ik python can only do one job at a time.Takes a subroutine while pausing everything else and then runs the subroutine, but for multi user u need to do multitask while python only does one job at a time

gilded remnant
cold sorrel
gilded remnant
short temple
#

You can do multiplayer with python of course

#

You can take a look to sockets and multithreading

gilded remnant
short temple
#

Yes

#

Let's stay here

#

More people can help, interact and give their experience

#

You can use sockets to communicate between devices, and threading to run multiple code at once

gilded remnant
short temple
#

You don't have to be specific on your questions

#

One idea of multiplayering is:
Have one thread that listen to data coming from the server, and modify the state of the game in consequences

#

And one thread that do the logic

#

(Or multiple if you separate logic and rendering)

#

And for a server, kinda the same. One thread per player listening to data, and one running the logic

#

In the logic, or in a separate thread, you can send the data to the players

gilded remnant
#

How do i make the game playable by others after handling all that?

short temple
#

You have two options: keeping all computations locally, based on the current state and the server's data, or compute everything in the server and send the current state to the players

short temple
#

The difference being: you'll have multiple players instances, and their values depends on the transmitted data

gilded remnant
#

Ohh

short temple
#

You can even consider data reception as events

gilded remnant
#

What’s your opinion performance- wise?

short temple
#

It should work fine

short temple
#

What I do is: consider data reception as events, handle them to change the game variables. For user inputs, take care of them directly and send the result to the server too

gilded remnant
#

Can’t i just make it await a set amount of time before transmitting?

short temple
#

An example of simple cars moving on a plane, you'll only send to the server the inputs. Every player knows when someone turns, accelerate or brake. Everything else is computed based on that

#

Yeah, my solution is to have N_players +2 threads in the server. N_players handle data send by each players, 1 handles the logic if any, and one sends data that needs to be sent

gilded remnant
#

That works

short temple
#

That's if you need to regularly send data, so more like option 2, for option 1, you send data whenever it makes sense to send them

#

You can also have some kind of a mix, with the sending thread sending data regularly to sync every player

#

And other data sent ocasionally by the logic thread

gilded remnant
short temple
#

Which attachement ?

gilded remnant
short temple
#

....

#

You didn't

gilded remnant
#

Try checking your spam maybe?

short temple
#

I gave you a broad idea on how to do it, if you have specific questions about that, please ask here

#

I won't look at your thousands to help you implement multiplayering

gilded remnant
#

No, i totally got the idea, appreciate the help. It’s just i am worried performance- wise

short temple
#

Don't worry about performances

#

You have worked 2 days

#

So you don't have something worth stealing

noble pine
short temple
#

Nor you have something complex enough to have bas performances

#

I mean, the multiplayer thing will not be too much of a problem really

gilded remnant
#

Thanks!

#

.close

#

?close

cold fulcrumBOT
#

This is not a Modmail thread.

short temple
#

!close

gilded remnant
#

!close

pearl ospreyBOT
#
Python help channel closed with !close

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.

short temple
#

It is