Why is my program doing this?

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
GhostAction
Prole
Posts: 34
Joined: Wed Apr 22, 2015 11:10 pm
Contact:

Why is my program doing this?

Post by GhostAction »

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!
Owner of Isocubic. (Developer of void²)
User avatar
Vimm
Party member
Posts: 113
Joined: Wed Mar 16, 2016 8:14 pm

Re: Why is my program doing this?

Post by Vimm »

just attach the .love file, dont post all the code lol, its easier that way
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Why is my program doing this?

Post by zorg »

Also, if you do want to post code, use

Code: Select all

[code] code tags 
[/code]
Me and my stuff :3True 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.
User avatar
GhostAction
Prole
Posts: 34
Joined: Wed Apr 22, 2015 11:10 pm
Contact:

Re: Why is my program doing this?

Post by GhostAction »

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²)
User avatar
Vimm
Party member
Posts: 113
Joined: Wed Mar 16, 2016 8:14 pm

Re: Why is my program doing this?

Post by Vimm »

GhostAction wrote:I couldn't get it to be a .love so I just attached main.lua and the server file as well:
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 .love
User avatar
GhostAction
Prole
Posts: 34
Joined: Wed Apr 22, 2015 11:10 pm
Contact:

Re: Why is my program doing this?

Post by GhostAction »

I have winrar so yeah... but is it that hard to put it into a folder?
Owner of Isocubic. (Developer of void²)
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Why is my program doing this?

Post by s-ol »

GhostAction wrote:I have winrar so yeah...
you know you can zip files with winrar too right?
but is it that hard to put it into a folder?
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.

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.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
GhostAction
Prole
Posts: 34
Joined: Wed Apr 22, 2015 11:10 pm
Contact:

Re: Why is my program doing this?

Post by GhostAction »

So how do you zip it with winrar then?
Owner of Isocubic. (Developer of void²)
User avatar
GhostAction
Prole
Posts: 34
Joined: Wed Apr 22, 2015 11:10 pm
Contact:

Re: Why is my program doing this?

Post by GhostAction »

I'm just going to uninstall winrar.
Owner of Isocubic. (Developer of void²)
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Why is my program doing this?

Post by s-ol »

GhostAction wrote:I'm just going to uninstall winrar.
Select the files. right click -> add to archive. Choose zip, change name to .love. As far as I remember, not on windows atm.

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....?

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 3 guests