This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
libraryaddict's profile picture

Render is not sent to first computer till it moves

Started by libraryaddict, 08 July 2012 - 12:51 AM
libraryaddict #1
Posted 08 July 2012 - 02:51 AM
http://www.computercraft.info/forums2/index.php?/topic/2460-gamepuzzle-maze-01/

Look in the mutliplayer bit.
There are 2 files.
Make the server then join 2 clients.
Move the 2nd client around.
On the first client you will not see it moving..

But if you move it then its fixed.

This shouldn't happen at all :s
I don't see a reason for it to happen.
Its not because I forget to render it.

Everytime something changes everything is re-rendered and resent.
For the 2nd computer to move, The first must be sent it as well.
Pinkishu #2
Posted 08 July 2012 - 01:54 PM
The problem is your server :)/>/>



function reDraw() -- Used for redrawing all clients into map and sending it out
  for n=1,#Clients do
    moveClient(n, Clients[n]["X"], Clients[n]["Y"], Clients[n]["Char"])
    moveScreen(Clients[n]["ID"], Clients[n]["X"]-(Clients[n]["Wide"]/2), Clients[n]["Y"]-(Clients[n]["High"]/2))
    draw(Clients[n]["ID"])
    local Cool = {returnView(Clients[n]["ID"])}
    rednet.send(Clients[n]["ID"], "draw"..textutils.serialize(Cool))
  end
  draw("Main")
  local G = {returnView("Main")}
  for n=1,#G do
    term.setCursorPos(1,n)
    term.write(G[n])
  end
end

Your moved() function which is called when a client moves only removes the client Char from the old position, doesn't place a new Char at its new position
now reDraw takes care of that though… but not fully, someitmes it would auto-correct itself through pings from what i've seen
But basically
you loop through the clients, you move each client and then send the array to them
so if client 2 moved you removed client 2's character

Loop Start client1
move client 1
send map to client1
Loop start clinet2
move client2
send map to client2

Notice the map you sent to client1 didn't move client2 yet, thus client2 is currently invisible



function reDraw() -- Used for redrawing all clients into map and sending it out
  for n=1,#Clients do
    moveClient(n, Clients[n]["X"], Clients[n]["Y"], Clients[n]["Char"])
  end
  for n=1,#Clients do
    moveScreen(Clients[n]["ID"], Clients[n]["X"]-(Clients[n]["Wide"]/2), Clients[n]["Y"]-(Clients[n]["High"]/2))
    draw(Clients[n]["ID"])
    local Cool = {returnView(Clients[n]["ID"])}
    rednet.send(Clients[n]["ID"], "draw"..textutils.serialize(Cool))
  end
  draw("Main")
  local G = {returnView("Main")}
  for n=1,#G do
    term.setCursorPos(1,n)
    term.write(G[n])
  end
end

might fix that: loop throuhg all clients and move them, then send each client the new map

or you might just set the new char at the end of the moved() function already

btw, from moveClients function

if Clients[n]["X"] == Clients[Client]["X"] and Clients[n]["X"] == Clients[Client]["X"] then
seems weird? did you mean "Y" at the latter part?
libraryaddict #3
Posted 08 July 2012 - 03:33 PM
The problem is your server :)/>/>



function reDraw() -- Used for redrawing all clients into map and sending it out
  for n=1,#Clients do
	moveClient(n, Clients[n]["X"], Clients[n]["Y"], Clients[n]["Char"])
	moveScreen(Clients[n]["ID"], Clients[n]["X"]-(Clients[n]["Wide"]/2), Clients[n]["Y"]-(Clients[n]["High"]/2))
	draw(Clients[n]["ID"])
	local Cool = {returnView(Clients[n]["ID"])}
	rednet.send(Clients[n]["ID"], "draw"..textutils.serialize(Cool))
  end
  draw("Main")
  local G = {returnView("Main")}
  for n=1,#G do
	term.setCursorPos(1,n)
	term.write(G[n])
  end
end

Your moved() function which is called when a client moves only removes the client Char from the old position, doesn't place a new Char at its new position
now reDraw takes care of that though… but not fully, someitmes it would auto-correct itself through pings from what i've seen
But basically
you loop through the clients, you move each client and then send the array to them
so if client 2 moved you removed client 2's character

Loop Start client1
move client 1
send map to client1
Loop start clinet2
move client2
send map to client2

Notice the map you sent to client1 didn't move client2 yet, thus client2 is currently invisible



function reDraw() -- Used for redrawing all clients into map and sending it out
  for n=1,#Clients do
	moveClient(n, Clients[n]["X"], Clients[n]["Y"], Clients[n]["Char"])
  end
  for n=1,#Clients do
	moveScreen(Clients[n]["ID"], Clients[n]["X"]-(Clients[n]["Wide"]/2), Clients[n]["Y"]-(Clients[n]["High"]/2))
	draw(Clients[n]["ID"])
	local Cool = {returnView(Clients[n]["ID"])}
	rednet.send(Clients[n]["ID"], "draw"..textutils.serialize(Cool))
  end
  draw("Main")
  local G = {returnView("Main")}
  for n=1,#G do
	term.setCursorPos(1,n)
	term.write(G[n])
  end
end

might fix that: loop throuhg all clients and move them, then send each client the new map

or you might just set the new char at the end of the moved() function already

btw, from moveClients function

if Clients[n]["X"] == Clients[Client]["X"] and Clients[n]["X"] == Clients[Client]["X"] then
seems weird? did you mean "Y" at the latter part?

:|

Yet again you solve a brick wall of mine!