Multiplayer Help

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.
Post Reply
User avatar
CanadianGamer
Party member
Posts: 132
Joined: Tue Jun 30, 2015 1:23 pm
Location: Canada
Contact:

Multiplayer Help

Post by CanadianGamer »

Hi I have recently been trying to make an online game so I went and read the networking tutorial on the wiki, but it didn't explain why you really have to format the string before sending from the server. Why is it necessary? Any help anyone could provide would be helpful
My serious itch.io page:
https://pentamonium-studios.itch.io/
My less serious itch.io page:
http://canadiangamer.itch.io
User avatar
veethree
Inner party member
Posts: 875
Joined: Sat Dec 10, 2011 7:18 pm

Re: Multiplayer Help

Post by veethree »

If you're referring to lines like this one

Code: Select all

local dg = string.format("%s %s %d %d", entity, 'at', 320, 240)
that's equivalent to

Code: Select all

dg = entity.." at "..320.." "..240
The point is to turn it into a single string like

Code: Select all

"*entity* at 320 240"
I would recommend having a look at enet for networking.
cval
Citizen
Posts: 58
Joined: Sun Apr 20, 2014 2:15 pm
Location: Ukraine

Re: Multiplayer Help

Post by cval »

Because string is basically array of bytes which is easy to work with: to compose on sender side and to process on receiver side using standard string libraries. You can set up communication without using strings and using your own encode-decode format, but your data is going to be a pack of bytes anyway.
Zvoc47
Prole
Posts: 2
Joined: Fri Apr 29, 2016 5:52 pm

Re: Multiplayer Help

Post by Zvoc47 »

I have a question. If I format the string, will it be sent as a string? Can I send packages as raw bytes to increase bandwidth?
User avatar
CanadianGamer
Party member
Posts: 132
Joined: Tue Jun 30, 2015 1:23 pm
Location: Canada
Contact:

Re: Multiplayer Help

Post by CanadianGamer »

Thank you guys so much I was getting really confused
My serious itch.io page:
https://pentamonium-studios.itch.io/
My less serious itch.io page:
http://canadiangamer.itch.io
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Multiplayer Help

Post by Robin »

Zvoc47 wrote:I have a question. If I format the string, will it be sent as a string?
Yes.
Zvoc47 wrote:Can I send packages as raw bytes to increase bandwidth?
No.

You can only send strings, because what's sent is the contents of the string, and they're sent as raw bytes.
Help us help you: attach a .love.
User avatar
GhostAction
Prole
Posts: 34
Joined: Wed Apr 22, 2015 11:10 pm
Contact:

Re: Multiplayer Help

Post by GhostAction »

Another easier way, in my opinion is having in loop through the data, finding every space, then separating the works/numbers/characters and then putting them into a table in order.

Code: Select all

for i in string.gmatch(receivedData, "%S+") do
	table.insert(command, i)
end
Then I use something like:

Code: Select all

if command[1] == "dog" then
print("cat")
end
command = {}
Just I little thing I found out. But the other way is great too, just never figured out how to use it lol.
Owner of Isocubic. (Developer of void²)
Post Reply

Who is online

Users browsing this forum: rabbitboots and 91 guests