So I'm trying to make a multiplayer game follow this guide: https://love2d.org/wiki/Tutorial:Networ ... -TheClient
For some reason whenever start up a client, its getting data from the user that joined before it and itself, not getting data from later joiners. If you don't understand, just copy and paste and try it out.
Here is the client code:
--Core Functions Load First
--Console
local consoleText = ""
local rounds = 10
function console(text)
rounds = rounds + 1
consoleText = text..string.char(10)..consoleText
if rounds > 40 then
consoleText = ""
rounds = 0
end
end
--Client
local width = love.graphics.getWidth()
local height = love.graphics.getHeight()
local state = "load"
local frames = 0
--Server
local socket = require "socket"
local address = "localhost"
local port = 2001
udp = socket.udp()
udp:settimeout(0)
udp:setpeername(address, port)
local world = {}
--Player
local playerName = os.time()
playerPositionX = 0
playerPositionY = 0
--Client Player
local CamPositionX = 395
local CamPositionY = 295
local keyFowardUp = false
local keyBackwardsUp = false
local keyLeftUp = false
local KeyRightUp = false
console("connecting to "..address..":"..port)
function love.update()
--Receiving Data from Server
local receivedData = udp:receive()
if receivedData then
local command = {}
console(receivedData)
for i in string.gmatch(receivedData, "%S+") do
table.insert(command, i)
end
if command[1] == "updatePos" then
world[command[2]] = {posX = command[3], posY = command[4]}
--[[for a, b in pairs(world) do
console(a.." X:"..b.posX.." Y:"..b.posY)
end]]--
end
command = {}
end
--Send Update Command to Server
udp:send("updatePos "..playerName.." "..playerPositionX.." "..playerPositionY)
end
function love.draw()
love.graphics.print(consoleText, 0, 0)
end
And the server code:
--Server
local socket = require "socket"
local udp = socket.udp()
udp:settimeout(0)
udp:setsockname("*", 2001)
local world = {}
local data, msg_or_ip, port_or_nil
local player, cmd, parms
local command = {}
local running = true
while running do
data, msg_or_ip, port_or_nil = udp:receivefrom()
if data then
for i in string.gmatch(data, "%S+") do
table.insert(command, i)
end
if command[1] == "updatePos" then
--print("Updating Position for "..msg_or_ip..":"..port_or_nil)
world[command[2]] = {posX = command[3], posY = command[4], ip = msg_or_ip, port = port_or_nil}
end
command = {}
end
for _, c in pairs(world) do
for a, b in pairs(world) do
print("Sending to "..c.ip..":"..c.port.." "..b.ip..":"..b.port.." info a:"..a)
udp:sendto("updatePos "..a.." "..b.posX.." "..b.posY, c.ip, c.port)
end
end
end
Thanks!
Why is my program doing this?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- GhostAction
- Prole
- Posts: 34
- Joined: Wed Apr 22, 2015 11:10 pm
- Contact:
Why is my program doing this?
Owner of Isocubic. (Developer of void²)
Re: Why is my program doing this?
just attach the .love file, dont post all the code lol, its easier that way
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Why is my program doing this?
Also, if you do want to post code, use
[/code]
Code: Select all
[code] code tags
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
- GhostAction
- Prole
- Posts: 34
- Joined: Wed Apr 22, 2015 11:10 pm
- Contact:
Re: Why is my program doing this?
I couldn't get it to be a .love so I just attached main.lua and the server file as well:
- Attachments
-
- server.lua
- (868 Bytes) Downloaded 120 times
-
- main.lua
- (1.53 KiB) Downloaded 124 times
Owner of Isocubic. (Developer of void²)
Re: Why is my program doing this?
what do you mean you couldnt get it to be a .love? you just put the files into a zip and then rename the .zip to .loveGhostAction wrote:I couldn't get it to be a .love so I just attached main.lua and the server file as well:
- GhostAction
- Prole
- Posts: 34
- Joined: Wed Apr 22, 2015 11:10 pm
- Contact:
Re: Why is my program doing this?
I have winrar so yeah... but is it that hard to put it into a folder?
Owner of Isocubic. (Developer of void²)
Re: Why is my program doing this?
you know you can zip files with winrar too right?GhostAction wrote:I have winrar so yeah...
Of course not. But you are asking us for help, and providing .love's is a forum "rule". Not only does a .love make it easier for us to help you (which is in your interest), it's also a bit of courtesy in a way.but is it that hard to put it into a folder?
By giving us a .love you make sure we have the exact files you are running, including misplaced images or scripts, typos and without copy and pasting errors. All of those things often amount to problems people have that we can't tell they have otherwise for example.
- GhostAction
- Prole
- Posts: 34
- Joined: Wed Apr 22, 2015 11:10 pm
- Contact:
Re: Why is my program doing this?
So how do you zip it with winrar then?
Owner of Isocubic. (Developer of void²)
- GhostAction
- Prole
- Posts: 34
- Joined: Wed Apr 22, 2015 11:10 pm
- Contact:
Re: Why is my program doing this?
I'm just going to uninstall winrar.
Owner of Isocubic. (Developer of void²)
Re: Why is my program doing this?
Select the files. right click -> add to archive. Choose zip, change name to .love. As far as I remember, not on windows atm.GhostAction wrote:I'm just going to uninstall winrar.
How will uninstalling winrar help? That's just one tool less that can accomplish the task. If you don't get along with winrar you will at least need to install something else....?
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 2 guests