Multiplayer

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Bigfoot71
Party member
Posts: 287
Joined: Fri Mar 11, 2022 11:07 am

Re: Multiplayer

Post by Bigfoot71 »

fridays18 wrote: Fri Feb 03, 2023 12:11 pm I finally figured out how to boot the server using shell, but now I have no clue how to do anything regarding connecting it to my main.lua file considering the github file is massive and theres not any info on how to require and change what on the github lol
Try this basic example which refreshes the average ping every second, if it works you can start learning and experimenting from it. (I rewrote the example given on the repository to make it more understandable and more functional/modular)

First start the server (the one in the .zip, to be sure because it's supposed to work):

Code: Select all

node server/node.js
Then launch with Löve.
Attachments
NoobHub-Demo.zip
(53.24 KiB) Downloaded 80 times
My avatar code for the curious :D V1, V2, V3.
User avatar
fridays18
Citizen
Posts: 90
Joined: Tue Nov 01, 2022 3:24 pm

Re: Multiplayer

Post by fridays18 »

Bigfoot71 wrote: Fri Feb 03, 2023 3:53 pm
fridays18 wrote: Fri Feb 03, 2023 12:11 pm I finally figured out how to boot the server using shell, but now I have no clue how to do anything regarding connecting it to my main.lua file considering the github file is massive and theres not any info on how to require and change what on the github lol
Try this basic example which refreshes the average ping every second, if it works you can start learning and experimenting from it. (I rewrote the example given on the repository to make it more understandable and more functional/modular)

First start the server (the one in the .zip, to be sure because it's supposed to work):

Code: Select all

node server/node.js
Then launch with Löve.
Its working great! the screen is printing the ping and the chat is communicating everything with no issues! Now to progress should I make a separate file (to run separately) to host all the server stuff and than just put all the client stuff in game?
User avatar
fridays18
Citizen
Posts: 90
Joined: Tue Nov 01, 2022 3:24 pm

Re: Multiplayer

Post by fridays18 »

Btw once again I really appreciate all the help youre providing Ive found it very hard finding good docs and getting a project like this I can just experiment with is gonna be amazing for understanding everything!
User avatar
Bigfoot71
Party member
Posts: 287
Joined: Fri Mar 11, 2022 11:07 am

Re: Multiplayer

Post by Bigfoot71 »

fridays18 wrote: Fri Feb 03, 2023 4:05 pm Its working great! the screen is printing the ping and the chat is communicating everything with no issues! Now to progress should I make a separate file (to run separately) to host all the server stuff and than just put all the client stuff in game?
I'm not really sure I understand your request but the client must be present in the game, this is what allows communication with the server and the "server" folder is what must actually be on the server.

You can even rewrite the script I gave you if you don't like it, in reality the real client is the noobhub.lua file, what is present in the client.lua file are the callbacks and the functions of updating the game with information received from the server, it doesn't matter how you use noobhub (from a "client" script or just from a "world" table which will contain the data received) as long as it works.

Although what I showed you personally seems like a pretty clean way to do it.

To be able to make a server you have several solutions, either pay a service like the one offered by DigitalOcean (you can find the tutorial that I shared with you here) or if you can't afford it you can do it very simply by installing Ubuntu Server on a PC (or a virtual machine if you have the courage) and follow tutorials so that your internet box benefits from a public IP address linked to your dedicated server.
Last edited by Bigfoot71 on Fri Feb 03, 2023 4:36 pm, edited 1 time in total.
My avatar code for the curious :D V1, V2, V3.
User avatar
fridays18
Citizen
Posts: 90
Joined: Tue Nov 01, 2022 3:24 pm

Re: Multiplayer

Post by fridays18 »

Bigfoot71 wrote: Fri Feb 03, 2023 4:31 pm
fridays18 wrote: Fri Feb 03, 2023 4:05 pm Its working great! the screen is printing the ping and the chat is communicating everything with no issues! Now to progress should I make a separate file (to run separately) to host all the server stuff and than just put all the client stuff in game?
I'm not really sure I understand your request but the client must be present in the game, this is what allows communication with the server and the "server" folder is what must actually be on the server.

To be able to make a server you have several solutions, either pay a service like the one offered by DigitalOcean (you can find the tutorial that I shared with you here) or if you can't afford it you can do it very simply by installing Ubuntu Server on a PC (or a virtual machine if you have the courage) and follow tutorials so that your internet box benefits from a public IP address linked to your dedicated server.
Ahh okay I see. My next question is how would I go about testing multiple clients connecting? I was able to give the client its own player which will be printed to the screen in main(it updates,draws and moves, through client) but when I made a second project identical to the current one and tried to run it I get this error

NoobHub: Attempt to publish without valid subscription (bad socket)
Noobhub: attempt to reconnect...
Noobhub connection error: connection refused
Problems with server..?
User avatar
Bigfoot71
Party member
Posts: 287
Joined: Fri Mar 11, 2022 11:07 am

Re: Multiplayer

Post by Bigfoot71 »

fridays18 wrote: Fri Feb 03, 2023 4:35 pm My next question is how would I go about testing multiple clients connecting? I was able to give the client its own player which will be printed to the screen in main(it updates,draws and moves, through client) but when I made a second project identical to the current one and tried to run it I get this error

NoobHub: Attempt to publish without valid subscription (bad socket)
Noobhub: attempt to reconnect...
Noobhub connection error: connection refused
Problems with server..?
The error is quite descriptive I don't see what added, but here is a more complete and commented version.

In this example the client will send our info to all other players entering a game via the `client:enter` method and we will receive their info over time. This is not the best technique, what would be ideal would be to do something like a waiting list or a lobby that would allow you to join the game only when you have received all the information from the players present (at least in the area of spawn).

Then the client puts our position in the `client.world` table and we will have to update our position in this table, we will send our position contained in this table and receive that of the others. Of course this can be optimized this is only an example of a function. The ideal here again would be to calculate the difference between the old position and the new one received from another player in order to create a more natural movement, because the server is not refreshed as many times as the number of images to be our screen and in addition the latency time (ping) can be high for another player, all this will create jerky movements with the example I give you, hence the idea of ​​calculating a delta of the positions and doing them move little by little. A good system like this can take a long time to set up, so focus on the essentials first.

With all this you should understand. Otherwise, regardless of the library used, it will be roughly the same principles, so to understand how to implement these techniques, you must already have plenty of Youtube tutorials on Unity or other that you can readapt.

Here is this new example, launch the server, launch the demo twice and contemplate the magic of multi :awesome:
Attachments
NoobHub-Demo.zip
(54.1 KiB) Downloaded 70 times
My avatar code for the curious :D V1, V2, V3.
User avatar
fridays18
Citizen
Posts: 90
Joined: Tue Nov 01, 2022 3:24 pm

Re: Multiplayer

Post by fridays18 »

Bigfoot71 wrote: Fri Feb 03, 2023 5:44 pm
fridays18 wrote: Fri Feb 03, 2023 4:35 pm My next question is how would I go about testing multiple clients connecting? I was able to give the client its own player which will be printed to the screen in main(it updates,draws and moves, through client) but when I made a second project identical to the current one and tried to run it I get this error

NoobHub: Attempt to publish without valid subscription (bad socket)
Noobhub: attempt to reconnect...
Noobhub connection error: connection refused
Problems with server..?
The error is quite descriptive I don't see what added, but here is a more complete and commented version.

In this example the client will send our info to all other players entering a game via the `client:enter` method and we will receive their info over time. This is not the best technique, what would be ideal would be to do something like a waiting list or a lobby that would allow you to join the game only when you have received all the information from the players present (at least in the area of spawn).

Then the client puts our position in the `client.world` table and we will have to update our position in this table, we will send our position contained in this table and receive that of the others. Of course this can be optimized this is only an example of a function. The ideal here again would be to calculate the difference between the old position and the new one received from another player in order to create a more natural movement, because the server is not refreshed as many times as the number of images to be our screen and in addition the latency time (ping) can be high for another player, all this will create jerky movements with the example I give you, hence the idea of ​​calculating a delta of the positions and doing them move little by little. A good system like this can take a long time to set up, so focus on the essentials first.

With all this you should understand. Otherwise, regardless of the library used, it will be roughly the same principles, so to understand how to implement these techniques, you must already have plenty of Youtube tutorials on Unity or other that you can readapt.

Here is this new example, launch the server, launch the demo twice and contemplate the magic of multi :awesome:
Ill try it later when I get some time thank you I cant wait to mess around with this one since the last one was pretty fun to explore and test with!
User avatar
Bigfoot71
Party member
Posts: 287
Joined: Fri Mar 11, 2022 11:07 am

Re: Multiplayer

Post by Bigfoot71 »

I take this opportunity to add, in the example I gave you there is no management for the disconnection of players, I think that if you have understood you will know how to add it but it can be interesting to write a custom love.quit function and also manage that in love.errorhandler why not.

Also my example does not imply it but you can use the channels to make several games on the same server, so it will require some adaptation at the level of the call of the table "game" which carries the same as the channel.

In short, you have to think of everything when making a multiplayer game ^^
My avatar code for the curious :D V1, V2, V3.
User avatar
fridays18
Citizen
Posts: 90
Joined: Tue Nov 01, 2022 3:24 pm

Re: Multiplayer

Post by fridays18 »

Bigfoot71 wrote: Fri Feb 03, 2023 8:21 pm I take this opportunity to add, in the example I gave you there is no management for the disconnection of players, I think that if you have understood you will know how to add it but it can be interesting to write a custom love.quit function and also manage that in love.errorhandler why not.

Also my example does not imply it but you can use the channels to make several games on the same server, so it will require some adaptation at the level of the call of the table "game" which carries the same as the channel.

In short, you have to think of everything when making a multiplayer game ^^
Yeah lol, I thought it would be as easy as connecting to a host and sending data back and forth (like 3 lines of code lol) but now im seeing its a lot more in depth
User avatar
togFox
Party member
Posts: 763
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

Re: Multiplayer

Post by togFox »

I got udp/tcp/enet (forget which) to work in my project. I'm not at home atm but you can Google Mars Lander on togfoxy github.

It works peer to peer on LAN but couldn't get it past my ISP into the internet. It might be simpler than your current approach.

EDIT: https://github.com/togfoxy/Mars-Lander-reboot

Uses sock.lua for LAN fun.
Current project:
https://togfox.itch.io/backyard-gridiron-manager
American football manager/sim game - build and manage a roster and win season after season
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 17 guests