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

Elevator controler(s) problem

Started by almanzo, 23 October 2014 - 04:53 PM
almanzo #1
Posted 23 October 2014 - 06:53 PM
Hi!

I am working on an elevator using elevator tracks from Railcraft combined with bundled cables from ProjectRed. The way I do it is simply to run an elevator track all the way through all floors, while having different coloured cables at different points.

If you've played around with elevator tracks, you know that redstone powers the entire line downwards then two blocks up, so in order to control where the cart stops one simply has to place a redstone signal two blocks down from where you want it to stop.

As of such, I've used one colour of ProjectRed cable for each floor. I also have one computer on each floor.

This is the program on them:



shell.run("clear")

while true do

  write("Select floor 1-7: ")
  local Floor = read()
  if Floor == "1" then
redstone.setBundledOutput("left", colors.red) 

if Floor == "2" then
redstone.setBundledOutput("left", colors.blue) 
end
if Floor == "3" then
redstone.setBundledOutput("left", colors.green) 
end
if Floor == "4" then
redstone.setBundledOutput("left", colors.yellow) 
end
if Floor == "5" then
   redstone.setBundledOutput("left", colors.white)
end
if Floor == "6" then
   redstone.setBundledOutput("left", colors.black)
end
if Floor == "7" then
   redstone.setBundledOutput("left", colors.brown)
end

end

Now, as you know, the command setBundledOutput makes the computer switch off all colour outputs before switching on the required colour. Until now, it's fine and dandy…

The problem however, arise due to the fact that I am using different computers on each floor. As SetBundledOutput only affects the output status on the computer currently in use, previously used computers (the ones on lower levels) won't turn off their bundledoutput and thus the elevator won't go down.


So what I figured out that I need to do, is to use wireless rednet to connect to the computer on the first floor and launch the program from there, rather than having a local version of the program on each floor, basicly turning the first floor computer into a server.

Thing is, I have no clue how to do this… Is it possible to access a program that is local to a computer over a rednet network, so that all of the computers are accessing the program from the "server" rather than executing the commands locally? If so, how do I go about doing this?
Bomb Bloke #2
Posted 23 October 2014 - 11:07 PM
Now, as you know, the command setBundledOutput makes the computer switch off all colour outputs before switching on the required colour.

Well, that's true of the way you're using it, sure. It's possible to enable multiple colours at once, then enable/disable colours without affecting the others. Not that that's relevant to the issue at hand, I'm just nit-picking… :P/>

Is it possible to access a program that is local to a computer over a rednet network, so that all of the computers are accessing the program from the "server" rather than executing the commands locally? If so, how do I go about doing this?

The short answer is no, not in the way you're thinking, unless you can get a system to accept multiple nsh sessions.

Well, technically you can do that whether nsh already supports it or not, but you get the idea. It'd be a fair bit of work.

Probably the simplest method would be to rig your script to use an advanced monitor, accepting input through the touch screen. Once that's done, just have one computer, then stick a monitor on each floor (all connected to the single system using network cable).
Dragon53535 #3
Posted 23 October 2014 - 11:33 PM
You could actually tell all the computers on the line to shut down and then start back up, thus wiping their current rs.setBundledOutput() if you connect them via wired modem.


modem = peripheral.wrap("side")
    for _,i in pairs(modem.getNamesRemote()) do --#Grab all the names of peripherals on the wired modems (computers count)
      if peripheral.getType(i) == "computer" then --#If the current peripheral is a computer
        peripheral.call(i,"shutdown") --#Tell the computer that it found to shutdown
        sleep(0)
        peripheral.call(i,"turnOn") --#Tell the computer that it found to start back up
      end
    end
This will grab the name of any peripheral connected and if it's a computer, turn it off and on by calling a command.

However if you're just wanting to send a rednet message to a "slave" computer that will do all the work, you can easily do rednet.send()

Say the controller computer's ID is 2 you could use this to send the message of what floor you're wanting to go to, and what you're going from.
Lets say you're on floor 2 and going to floor 8


local modemside = "right" --#side the wireless/wired modem is on
rednet.open(modemside) --#Open the wireless/wired modem for rednet
local tbl = {going = "8", coming = "2"} --# This is a table that i'm sending to the server
rednet.send(2,tbl) --#Sending tbl to the computer who's ID is 2
And then on the server you could use
local modemside = "right"
rednet.open(modemside)
local id,msg = rednet.receive()--#This will wait until it gets a rednet message. id is the id of who sent, msg is the message sent.
if msg.going == "8" then --#If we told it we're going to 8
  --Do stuff
end
if msg.coming == "2" then --#If we told it we're coming from 2
  --Do stuff
end
You would need to alter it to suit your needs, however this should get you started on a path.
Edited on 23 October 2014 - 09:35 PM
almanzo #4
Posted 24 October 2014 - 01:35 AM
Now, as you know, the command setBundledOutput makes the computer switch off all colour outputs before switching on the required colour.

Well, that's true of the way you're using it, sure. It's possible to enable multiple colours at once, then enable/disable colours without affecting the others. Not that that's relevant to the issue at hand, I'm just nit-picking… :P/>

Is it possible to access a program that is local to a computer over a rednet network, so that all of the computers are accessing the program from the "server" rather than executing the commands locally? If so, how do I go about doing this?

The short answer is no, not in the way you're thinking, unless you can get a system to accept multiple nsh sessions.

Well, technically you can do that whether nsh already supports it or not, but you get the idea. It'd be a fair bit of work.

Probably the simplest method would be to rig your script to use an advanced monitor, accepting input through the touch screen. Once that's done, just have one computer, then stick a monitor on each floor (all connected to the single system using network cable).

That's initially what I thought of doing, but I ended up ditching the idea because it sounded to difficult so I settled with this one instead… Also, it looks alot cooler that way. Typically me, I usually go in well over my head. I am far from being a programmer, to be honest.

Any good tutorials that are easy to understand on how to program these monitors? From what I understand, I need an event handler?
almanzo #5
Posted 24 October 2014 - 02:44 AM
However if you're just wanting to send a rednet message to a "slave" computer that will do all the work, you can easily do rednet.send()

Say the controller computer's ID is 2 you could use this to send the message of what floor you're wanting to go to, and what you're going from.
Lets say you're on floor 2 and going to floor 8


local modemside = "right" --#side the wireless/wired modem is on
rednet.open(modemside) --#Open the wireless/wired modem for rednet
local tbl = {going = "8", coming = "2"} --# This is a table that i'm sending to the server
rednet.send(2,tbl) --#Sending tbl to the computer who's ID is 2
And then on the server you could use
local modemside = "right"
rednet.open(modemside)
local id,msg = rednet.receive()--#This will wait until it gets a rednet message. id is the id of who sent, msg is the message sent.
if msg.going == "8" then --#If we told it we're going to 8
  --Do stuff
end
if msg.coming == "2" then --#If we told it we're coming from 2
  --Do stuff
end
You would need to alter it to suit your needs, however this should get you started on a path.

This seems like a good idea, however there is no point in having the slave or the server knowing what floor one is on, as long as it knows where I want it to go.

Thank you, I'll think I'll use this.
Dragon53535 #6
Posted 24 October 2014 - 03:29 AM
This seems like a good idea, however there is no point in having the slave or the server knowing what floor one is on, as long as it knows where I want it to go.

Thank you, I'll think I'll use this.
If you're going to just use the where i'm going to, you can just send that variable itself rather than a table.

The reason I used coming from and going to, is that i didn't know how your rail system worked :P/>
Edited on 24 October 2014 - 01:30 AM
almanzo #7
Posted 24 October 2014 - 03:56 AM
I got it working!!!

Thank you Dragon 53535!

I ended up scrapping the "local tbl"

and instead simply just make it like this:


if Floor == "3" then
local modemside = "right"
rednet.open(modemside)
rednet.send(25,"3")

And yes, it might be a tad sloppy to use string input instead of integer, but yeah, it works. It was at least much easier to just send the value directly instead of forcing the server to get it from a table.

Nontheless, without your help I would not have been able to do this. Thank you both, I never actually thought that I would be able to get this today! Thanks!

Edit: Ah, I didn't refresh the page before replying.

It's quite straight forward actually, I'll make a video on youtube on it some time during the weekend.


I've been searching around youtube for simular designs without any luck to my suprise. It's not a very complicated build, yet it's quick, effective and doesn't take up much room. The only better alternative in my mind is pheumatic craft, and then you won't get to play with computers :P/> Their elevators are quite cool, but a tad to easy to build for my taste. One needs at least some challange :P/>
Edited on 24 October 2014 - 01:58 AM
Dragon53535 #8
Posted 24 October 2014 - 04:04 AM
Technically to cut down on your code you can do

local modemside = "right"
rednet.open(modemside)
if Floor == "3" then
  rednet.send(2,3)
elseif Floor == "4" then
  rednet.send(2,4)
end
You can send numbers as well :P/>
Edited on 24 October 2014 - 02:04 AM
mrdawgza #9
Posted 24 October 2014 - 03:48 PM
I did this a couple days ago.

On each floor I had a two computers and modems, that is all.

I had one computer behind the rail giving power to each section. Now if I put redstone power on the 5th floor, all floors below would be on.
The computer behind the rail is not visible.

The selection computer (where it displays floor numbers) is visible.
Heres the code for the selection computer(s):

Computer number 4 for example
Spoiler

while true do

rednet.open("back")

local function clear(x,y)
 term.clear()
 term.setCursorPos(x,y)
end



clear(1,1)

print("You are on level 1")
print("[1]")
print("[2]")
print("[3]")
print("[4]")
print("[5]")
print("[6]")
print("[G]")
print("")
print("[Call]")
print("[Roof]")

local event, button, x, y = os.pullEventRaw()
if event == "mouse_click" then
 if x>1 and x<3 and y==1 and button==1 then
  rednet.broadcast("off")
  rednet.send(13, "on") --The ID here is for the 1st floor
 elseif x>1 and x<3 and y==2 and button==1 then
  rednet.broadcast("off")
  rednet.send(12, "on")
 elseif x>1 and x<3 and y==3 and button==1 then
  rednet.broadcast("off")
  rednet.send(11, "on")
 elseif x>1 and x<3 and y==4 and button==1 then
  rednet.broadcast("off")
  rednet.send(9, "on")
 elseif x>1 and x<3 and y==5 and button==1 then
  rednet.broadcast("off")
  rednet.send(7, "on")
 elseif x>1 and x<3 and y==6 and button==1 then
  rednet.broadcast("off")
  rednet.send(6, "on")
 elseif x>1 and x<3 and y==7 and button==1 then
  rednet.broadcast("off")
  rednet.send(4, "on")
 elseif x>1 and x<3 and y==8 and button==1 then
  rednet.broadcast("off")
 elseif x>1 and x<6 and y==10 and button==1 then 
  rednet.broadcast("off")
  rednet.send(12, "on")
 elseif x>1 and x<6 and y==11 and button==1 then 
  rednet.broadcast("off")
  rednet.send(13, "on")

 else
 end
end

sleep(0.5)
end

and here is the code for the power computers (non visible)

Computer number 5 for example
Spoiler

while true do

rednet.open("bottom")
local senderId, message = rednet.receive()

if message == "on" then
  redstone.setOutput("left", true)
 elseif message == "off" then
  redstone.setOutput("left", false)
end
end

Computer number 5 is always looking for a message. Now if you want to go down on computer 4, it has to tell all power computers about this change, so it broadcasts 'off' to them so they turn off the redstone output, immediately after it sends 'on' to the power computer on the floor you requested (id 5 for example)


If you have any questions about this I can explain it more through a PM or Skype.
If you want I can make a video tutorial on this.
Edited on 24 October 2014 - 01:48 PM