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

Elevator system with 15 floors

Started by ololulu, 28 October 2012 - 08:07 AM
ololulu #1
Posted 28 October 2012 - 09:07 AM
Hey i'm trying to figure out how to make elevator with 15 floors (15 computers).
I'm new to computercraft and i have no idea how to make it work.
I can use 1 computer to give signals to bundled cables.

1)Is there a way to make all computers be the same?
As in on floor 1 i write something and all other computers do the same?

2)How can i make computer 2 receive and wait for input same time?
("enter floor number: " and wait for other computer signal same time)

Is there any other way to make this work?

Thanks.

Been trying different things and cant get it to work.
Whats is wrong with this one?


file-"Startup"

test = "false"
while test=="false" do
shell.run("lift")
end


file-"lift"

rednet.close("left")
rednet.open("left")
write"Enter Floor Number: "
input = read()
if input=="2" then
rs.setBundledOutput("back", 2)
rednet.broadcast("off")
test = "true"
else
rs.setBundledOutput("back", 0)
rednet.broadcast("off")
end

file "off":

rednet.open("left")
msg = os.pullEvent()
if msg == "off" then
rs.setBundledOutput("back", 0)
rednet.close("left")
end
os.reboot(1)
Fashter #2
Posted 28 October 2012 - 09:18 AM
1) Yes, if you label a computer, and break it in creative mode, you can place it down infinitely in creative mode, and a file change on one computer will take effect on the others. Alternatively, you could rig up a rednet system to keep the computers in sync.

2) You can use os.pullevent()
Example for a computer that waits for a redstone signal and a rednet signal at the same time!

ev, id, msg = os.pullEvent() --Telling the computer to wait for an event
if ev == "rednet_message" then --If the event is a rednet_message then do some stuff
  if msg == "Emit a signal on the right" then --If the event was a rednet message, check what the message was
   redstone.setOutput("right",true) --If the message was valid, emit a redstone signal on the right
  elseif msg == "Don't emit a signal on the right" then --If it wasn't the above message then check if the rednet message was this one
   redstone.setOutput("right",false) --If it was this message then don't emit a redstone signal on the right
elseif ev == "redstone" then --If the event was a redstone change
  if rs.getInput("left") == true then --If the redstone change was on the left and the left got a redstone signal, do some stuff
   rednet.broadcast("Emit a signal on the right") --Broadcast a rednet signal that tells another computer to-do stuff

Hope this helps!
ololulu #3
Posted 28 October 2012 - 09:29 AM
1) Not in creative.
2) i'll try to figure something out with this.
ChunLing #4
Posted 28 October 2012 - 09:44 AM
Use os.pullEvent to be able to react to different kinds of events, like rednet messages and key/char input.
ololulu #5
Posted 28 October 2012 - 11:07 AM
Been trying different things and cant get it to work.
Whats is wrong with this one?


file-"Startup"

test = "false"
while test=="false" do
shell.run("lift")
end


file-"lift"

rednet.close("top")
rednet.open("top")
write"Enter Floor Number: "
input = read()
if input=="2" then
rs.setBundledOutput("back", 2)
rednet.broadcast("off")
test = "true"
else
rs.setBundledOutput("back", 0)
rednet.broadcast("off")
end

file "off":

rednet.open("left")
msg = os.pullEvent()
if msg == "off" then
rs.setBundledOutput("back", 0)
rednet.close("left")
end
os.reboot()
sjele #6
Posted 28 October 2012 - 11:19 AM
os.pullEvent captures events not messages. You can use rednet.receive to get the messages
Example:


local sender, message, distance = rednet.receive()
--Sender = senders computers id
--Message = the message
--Distance is the distance between computers

--With this info we can create a basic command receiver:
--the sending computers has sent his cmd
local send, msg,_ = rednet.receive() --_ discards stuff (stuff we don't need)
if msg == "off" then
  --Do stuff to make it offline
elseif msg == "on" then
--Do stuff to make it online
elseif msg == "kill" then
  --do stuff to "kill" it.
end

startup:
lift:
off:
Those will error as there is nothing called list: etc. or are they programs?

EDIT: os.pullEvent(filter) waits for events. The filter is the type of event and is opional. if no filter is given it waits for any event. (rednet, redstone, etc.)
ChunLing #7
Posted 28 October 2012 - 11:26 AM
Okay, there is no such event as "off". os.pullEvent has multiple returns, the first return is a string which describes the type of event, the later returns (the number of returns varies by event type) would contain more information. Check here for more details. Fortunately, the redstone event doesn't have any other returns, it just will be "redstone". So "if msg = "redstone" then " check the state of your redstone inputs.
ololulu #8
Posted 28 October 2012 - 11:51 AM
Okay, there is no such event as "off". os.pullEvent has multiple returns, the first return is a string which describes the type of event, the later returns (the number of returns varies by event type) would contain more information. Check here for more details. Fortunately, the redstone event doesn't have any other returns, it just will be "redstone". So "if msg = "redstone" then " check the state of your redstone inputs.
These are programs.



file-"Startup"

test = "false"
while test=="false" do
shell.run("lift")
end


file-"lift"

rednet.close("left")
rednet.open("left")
write"Enter Floor Number: "
input = read()
if input=="2" then
rs.setBundledOutput("back", 2)
rednet.broadcast("off")
test = "true"
else
rs.setBundledOutput("back", 0)
rednet.broadcast("off")
end

file "off":

rednet.open("left")
msg = os.pullEvent()
if msg == "off" then
rs.setBundledOutput("back", 0)
rednet.close("left")
end
os.reboot(1)
sjele #9
Posted 28 October 2012 - 12:10 PM
os.pullEvent captures events not messages. You can use rednet.receive to get the messages
Example:


local sender, message, distance = rednet.receive()
--Sender = senders computers id
--Message = the message
--Distance is the distance between computers

--With this info we can create a basic command receiver:
-- FROM HERE -----------------------------------------------------------------------------------------------------
--the sending computers has sent his cmd
local send, msg,_ = rednet.receive() --_ discards stuff (stuff we don't need)
if msg == "off" then
  --Do stuff to make it offline
elseif msg == "on" then
--Do stuff to make it online
elseif msg == "kill" then
  --do stuff to "kill" it.
end
--TO HERE ----------------------------------------------------------

startup:
lift:
off:
Those will error as there is nothing called list: etc. or are they programs?

EDIT: os.pullEvent(filter) waits for events. The filter is the type of event and is opional. if no filter is given it waits for any event. (rednet, redstone, etc.)

That should tell you how to do it.
Read the quote
ololulu #10
Posted 28 October 2012 - 12:11 PM
if i do it with rednet.receive it means i cant enter what floor i want to go since it will wait for the input from other computer.
sjele #11
Posted 28 October 2012 - 12:18 PM
First off indenting is important, here is a messy example. While i try to make this work for you, you can read that. http://pastebin.com/5xBwgT23

/me is trying to fix this code


Edit 1 : Is this all in one code?
ololulu #12
Posted 28 October 2012 - 12:21 PM
Edit 1 : Is this all in one code?
Right now it isn't in 1 code- there are 3 files.
sjele #13
Posted 28 October 2012 - 12:22 PM
In one or 3 computers?
ololulu #14
Posted 28 October 2012 - 12:33 PM
In one or 3 computers?
3 files in 1 computer.
But i am still having problems disabling cpu#1 signal with cpu#2.
There will be 15 computers in the end.

If only there was a way to make all computers work the same program, if i touch cpu#1 then cpu#2 does the same thing- it would be pretty simple(synchronizing).