Page 1 of 1
Multiplayer Help
Posted: Wed Apr 27, 2016 5:09 pm
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
Re: Multiplayer Help
Posted: Fri Apr 29, 2016 5:42 pm
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
I would recommend having a look at
enet for networking.
Re: Multiplayer Help
Posted: Fri Apr 29, 2016 6:21 pm
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.
Re: Multiplayer Help
Posted: Fri Apr 29, 2016 9:00 pm
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?
Re: Multiplayer Help
Posted: Fri Apr 29, 2016 10:43 pm
by CanadianGamer
Thank you guys so much I was getting really confused
Re: Multiplayer Help
Posted: Tue May 17, 2016 10:43 pm
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.
Re: Multiplayer Help
Posted: Wed May 18, 2016 12:44 am
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.