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

Tri- Computer Interaction (Solved)

Started by Jman, 30 July 2013 - 11:02 PM
Jman #1
Posted 31 July 2013 - 01:02 AM
Okay So I'm trying to create a password system for a group of computers so that they may open and close a set of pistons set into three different groups. But I keep having issues with the inter action between them and because I can't get the interaction between the receiver computer and the first sender computer to cooperate I cant even attempt to fail at writing the code for the second sender. Here this Picture Should help me make things a little bit more clear so I can point out my issue.

[attachment=1279:2013-07-31_02.16.16.jpg]

1. Receiver The computer in the bottom left hand corner of the screen shot. The receiver is supposed to carry out the actions the senders tell the receiver to do as well as say what part of the code it is working on and what how many cycles it has completed.

--FUNCTIONS
function PRDR(a)
  if message == "*-|" then
	d = colors.combine( colors.orange, colors.magenta)
	f = colors.subtract(f, colors.white)
	rs.setBundledOutput("bottom", d, f)
  elseif message == "-*|" then
	d = colors.subtract(d, colors.orange, colors.magenta)
	f = colors.combine(f, colors.white)
	rs.setBundledOutput("bottom", d, f)
  end

  if a == 1 then
	d = 1 + d
  end
end
function MLC()
  PRDR()
  coroutine.yeild()
  PRDR(1)
end

--CODE
CrCmd = coroutine.create(MLC)
rednet.open("back")
d = 1
while true do
  term.clear()
  term.setCursorPos(1,1)
  print("Phase - 1")
  message = rednet.receive()
  coroutine.resume(CrCmd)
  sleep(1)
  print("Phase - 2")
  message = rednet.receive()
  coroutine.resume(CrCmd)
  sleep(1)
  print("Cycle - "..d)
end

2.Sender_1 Then computer on the upper left hand side of the screenshot is Sender 1. Sender 1 is responsible for providing a password GUI to users so that one may not just walk into my friend and I's house. The password system is set to be flexible so that new passwords can easily be added later. Sender 1 is also supposed to multi- task almost all the time,(this bit I can't figure out) When the password program is running sender 1 is also supposed to monitor for interaction with sender two incase someone is coming out and needs to leave. when sender 2 sends it's message to the receiver it also sends a message to sender 1. telling Sender 1 that it needs to stop waiting for someone to press a key and enter in a password and instead to print ("PRESS ENTER TO CLOSE") on the screen and wait for someone to press the 'ENTER' key then tell the receiver to close the door. When sender 1 tells the receiver to open the door it sends a message to Sender 2 telling it that the user is on its way and it has to load the close door option and do nothing else until the door has been closed, then Sender 1 resets and waits again for the user or sender 2 to tell it its in charge of closing the door.

[code]term.clear()
term.setCursorPos(1,1)
rednet.open("back")
write ("Password: ")
input = read("*")
a = "."
d = 0
while true do
  term.setCursorPos(1,2)
  print("analyzing"..a.. ..b.. ..c)  -- causes error and i can't get the code to add a period on every time an second elapses for 3 consecutive seconds
  sleep(1)
  a = a + "."
  if d == 3 then
	  break
  end
  d = 1 + d
end
if input == "25434673" then
  rednet.send(0, "*-|")
  rednet.send(2, "open")
  term.setCursorPos(1,2)
  print("Welcome, Jordan!")
elseif input == "cantley" then
  rednet.send(0, "*-|")
  rednet.send(2, "open")
  term.setCursorPos(1,2)
  print("Welcome, Adam!")
end

3.Sender 2 The computer near the middle of the screen in the far back is Sender 2. Sender 2 has the same description as Sender 1 except Sender two waits for sender 1 or the user to press enter twice because your inside and there is no need for a password anymore.


-- no code for Sender 2
-- I can't write Sender 2's code because I'm stuck and have simulated everything on other CC computers on another world and just can't seem to figure out how to make S1 and S2 work together as described in Sender 1's description.
-- I also can't figure out the issue with the while loop for the 'analyzing' loop simulating a loading delay for reading and checking the password. It don't want to add an extra period after each loop until d reaches 3.

Please help I don't know what to do anymore. I'm seriously stumped and can't figure out anything that seems to work to my specifications. My friend and I would greatly appreciate it.

Thank You, and Happy Coding

P.S. - We are using CC for minecraft 1.4.7, couldn't find a redpower release for MC version 1.5.1 so never bumped it up a notch.
Jman #2
Posted 31 July 2013 - 02:16 AM
Nobody here can view an image stored on your hard drive. If you must demonstrate your issue with a picture, you'll have to upload it to some sort of hosting service and give us the link. You'd probably be better off just uploading your code to pastebin and giving us the link to that instead.

I just attached the picture, seems to show up on the computers all around my household.
jesusthekiller #3
Posted 31 July 2013 - 04:35 AM
If you posted link to your HDD, you are sure that you want to learn programming?
LBPHacker #4
Posted 31 July 2013 - 06:44 AM
Using that way of multitasking (coroutines) is pointless in this case. I'm in a good mood today, so I'm going to write the code for you (doesn't happen too often), and I'm going to describe the logic behind it right now.

Receiver
  • wait for message "open" (that means 'something like open', not exactly 'open' - it could be anything) (could be sent by any of the senders)
  • send the message for both senders "closeinterface" (again, could be anything, and same with the other messages)
  • open the gate (or set up the bridge, whatever)
  • wait for message "close" (again, could be sent by any of the senders)
  • send the message for both senders "openinterface"
  • close the gate
Sender #1 (with password) (currently the GUI is in input-password mode)
  • wait for an event
  • > if the event was "key"
    • > if the key was enter
      • > if the GUI is in input-password mode
        • check the password
        • > if correct
          • send the message "open" to the receiver
        • > if not correct
          • whatever, you can do anything you want
      • > if the GUI is not in input-password mode
        • send the message "close" to the receiver
    • > if the key was not an enter and the GUI is in input-password mode
      • register keystrokes - essentially inputting the password
  • > elseif the event was a rednet_message (and came from the receiver)
    • > if the message was "closeinterface"
      • switch the GUI to wait-for-enter mode
    • > elseif the message was "openinterface"
      • switch the GUI to input-password mode
Same with Receiver #2, but the input-password mode is the same as wait-for-enter mode.
LBPHacker #5
Posted 31 July 2013 - 08:06 AM
Receiver: http://pastebin.com/12v7exmw
Sender #1: http://pastebin.com/WNnQ50zn
Sedner #2: http://pastebin.com/2T7AZtvH

Don't forget to configure them (modem side, computer IDs)
Jman #6
Posted 31 July 2013 - 02:57 PM
If you posted link to your HDD, you are sure that you want to learn programming?
I know how to use programming it's just I never posted pics on here before. It was new to me.
Jman #7
Posted 31 July 2013 - 09:30 PM
Receiver: http://pastebin.com/12v7exmw
Sender #1: http://pastebin.com/WNnQ50zn
Sedner #2: http://pastebin.com/2T7AZtvH

Don't forget to configure them (modem side, computer IDs)
It works TYVM, took a lot of messing around with to understand what was going on. But it works. I used it on a different pair of computers on my rear exit because it wasn't too flexible to my extent of knowledge and instead just wrote another program for the entrance in the picture at the beginning of the topic. Having issues with the receiver for some reason not working. No clue as to why but that's another story but thanks and great explanation. helped me understand a big majority of it.