#🔒 Multiplayer with Python
66 messages · Page 1 of 1 (latest)
@gilded remnant
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.
I think python itself can't do that for example discord bot games need async await cuz when python takes an input from a user it can't take another input from another user it can only do one job at a time so......
So async await is used
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
Would you mind having a Private discussion?
Nope I m also a beginner no point in asking me
Thanks.
You can do multiplayer with python of course
You can take a look to sockets and multithreading
Mind having a private discussion?
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
It’s just that i’d like to keep my project private for a bit.
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
How do i make the game playable by others after handling all that?
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
Second.
Basically, once you handle the connection and the data transmission, everything is like a single player game
The difference being: you'll have multiple players instances, and their values depends on the transmitted data
Ohh
You can even consider data reception as events
What’s your opinion performance- wise?
It should work fine
In reality you'll use something in-between. In the second option, you may have too much data to transmit. In the first one, you could end up having desynchronisation
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
Can’t i just make it await a set amount of time before transmitting?
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
That works
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
Would you mind taking a look over the sent attachment?
Which attachement ?
PMed it to you.
Try checking your spam maybe?
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
No, i totally got the idea, appreciate the help. It’s just i am worried performance- wise
Don't worry about performances
You have worked 2 days
So you don't have something worth stealing
Nor you have something complex enough to have bas performances
I mean, the multiplayer thing will not be too much of a problem really
Agreed with that.
Thanks!
.close
?close
This is not a Modmail thread.
!close
!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.
It is