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

[LUA][Question]Making 2 PC's read/write from same path?

Started by remiX, 09 October 2012 - 05:29 PM
remiX #1
Posted 09 October 2012 - 07:29 PM
I'm using two computers to control a 'garage' door for my multiplayer server but they are reading and writing to their own ID folders. So when I open the door from the outside computer, it will update and make the status open whilst the computer inside will still have the closed status.

So how to I make both of these computers read and write to the same designated path?
Lyqyd #2
Posted 09 October 2012 - 07:32 PM
You can't, without some rednet file teleportation magic. The easier solution is to simply have whichever computer just opened or shut the door tell the other one what it just did (via rednet) and for that computer to update its file accordingly.
remiX #3
Posted 09 October 2012 - 07:44 PM
You can't, without some rednet file teleportation magic. The easier solution is to simply have whichever computer just opened or shut the door tell the other one what it just did (via rednet) and for that computer to update its file accordingly.

Damn. that just sucks :S

I've never used rednet before. How would I go about using rednet? Would I make it that if I recieve a signal from which ever side, it would change the status of the door to the opposite? hmm seems easy?
Lyqyd #4
Posted 09 October 2012 - 07:49 PM
You can't, without some rednet file teleportation magic. The easier solution is to simply have whichever computer just opened or shut the door tell the other one what it just did (via rednet) and for that computer to update its file accordingly.

Damn. that just sucks :S

Is this why you've been trying to write to the rom? Really, a simple rednet file server with an fs/io API modification can get you the single-path read-write functionality you're looking for. LyqydNet has this, though you may wish to implement your own.

Edit: To reply to your edit, you might want to check out the rednet tutorials in the tutorials section of the forums. All you really need is send an "open" or "closed" signal and receive it on the other end. If the computers are close enough, you could even send these through bundled cable or plain redstone, though not as rednet signals in the case of plain redstone.
nolongerexistant #5
Posted 09 October 2012 - 09:10 PM
You could use the HTTP api and make the pc's check for changes and then download it, or use rednet
OmegaVest #6
Posted 09 October 2012 - 09:23 PM
There is, in fact, a simpler solution. Since I assume both machines are feeding into the same redstone line (please correct me if I'm wrong), you could always just have them both watch for the redstone to fire, then update that way. Of course, if there are any repeaters in the way, then you will need to make a two-way repeater, which is neither fun nor easy, but can be done.
remiX #7
Posted 10 October 2012 - 01:31 PM
You can't, without some rednet file teleportation magic. The easier solution is to simply have whichever computer just opened or shut the door tell the other one what it just did (via rednet) and for that computer to update its file accordingly.

Damn. that just sucks :S

Is this why you've been trying to write to the rom? Really, a simple rednet file server with an fs/io API modification can get you the single-path read-write functionality you're looking for. LyqydNet has this, though you may wish to implement your own.

Edit: To reply to your edit, you might want to check out the rednet tutorials in the tutorials section of the forums. All you really need is send an "open" or "closed" signal and receive it on the other end. If the computers are close enough, you could even send these through bundled cable or plain redstone, though not as rednet signals in the case of plain redstone.

Yeah, thats the reason I've been trying to write to rom this whole time. I actually did use a code that uses simple plain redstone but I had come to a stop because of a problem: Obviously both PC's run off the same program, but this program requires you to enter a password which pauses the whole code (if im not correct? well thats where my problem comes in). When it asks for the user to supply a password it pauses it until the correct password is correct? I made mine do this:
while true do
if rs.getInput("right") then
  UpdateStatus()
  print("Attempting to update status")
  sleep(5)
else
  if fs.exists(sRoot.."SFGarageDoorStatus") then
    file = fs.open(sRoot.."SFGarageDoorStatus.txt", "r")
    if file then
	  sDoorStatus = file.readLine()
	  file.close()
	  print("Read status: "..sDoorStatus)
    else
	  print("Failed to read status")
    end
  else
    fs.makeDir(".savedVars")
  end
  CheckStatus()
end
end

Where is it has
  print("Attempting to update status")
I used this to check if it works when getting a signal and it does but when I destroy that signal from it then goes into the part where it needs a password and when I give it a signal again it does nothing because it requires a password. And the computers have only a block of space inbetween them.

I'm going to learn about rednet and all that stuff. Could I maybe take a look at your LyqydNet code? So I have some idea of how to put it all together.

You could use the HTTP api and make the pc's check for changes and then download it, or use rednet

I might also use my server for just LAN where no internet connection is available.

There is, in fact, a simpler solution. Since I assume both machines are feeding into the same redstone line (please correct me if I'm wrong), you could always just have them both watch for the redstone to fire, then update that way. Of course, if there are any repeaters in the way, then you will need to make a two-way repeater, which is neither fun nor easy, but can be done.

Yeah, they're feeding into the same redstone line to the door. Like I said to Lyqyd, I have a problem with the updating when getting a redstone signal.
Doyle3694 #8
Posted 10 October 2012 - 08:42 PM
ROM = Read Only Memory, and good luck writing to that… just saying xD