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

Elevator Program Trouble

Started by ProfessorTenebrae, 01 March 2014 - 04:20 AM
ProfessorTenebrae #1
Posted 01 March 2014 - 05:20 AM
Okay I'm trying to make an elevator using Computer Craft and Redstone In Motion, so I got a pretty nice setup going here (shown in the image)

It was operated by levers but I want it to look better, but I realise that I'm having huge trouble programming such a thing, (I'm not used to Lua see, C++ and Java are my areas, and while they are similar, I'm still having trouble.)


So my question is this, given the setup in the picture, where the red wire makes the elevator go down and the blue one go up, how can I get the computer to send a continuous redstone pulse through them for a set amount of time when the buttons are pressed to start the elevator?

I don't need to tell the computer to stop the pulses, the timer will do that, as the elevator will stop automatically when it hits something.

http://postimg.org/image/8c2vq16i7/
CometWolf #2
Posted 01 March 2014 - 09:28 AM
Should be farily simple

local elevatorTime = 20 --idk how long you want it
local red,blue
while true do
  local tEvent = {os.pullEvent()} -- this is a big part of CC lua, if you don't know what it is, i suggest you read up on it
  if tEvent[1] == "redstone" then
    if rs.getInput"left" then
      rs.setBundledOutput("bottom",colors.red)
      red = os.startTimer(elevatorTime)
    elseif rs.getInput"right" then
      rs.setBundledOutput("bottom",colors.blue)
	  blue = os.startTimer(elevatorTime)
    end
  elseif tEvent[1] == "timer" then
    if tEvent[2] == blue then
	  rs.setBundledOutput("bottom",colors.subtract(rs.getBundledOutput"bottom",colors.blue))
    elseif tEvent[2] == red then
	  rs.setBundledOutput("bottom",colors.subtract(rs.getBundledOutput"bottom",colors.red))
    end
  end
end
I didn't bother to explain much of what im doing, given your coding background i assume you understand most of it, and or ar able to look up documentation yourself.
Do note however that this code allowes input even if the elevator is currently moving, this could be changed if you wish.
Edited on 01 March 2014 - 08:37 AM
ProfessorTenebrae #3
Posted 02 March 2014 - 04:47 AM
No that's great! Thanks! I learn better from analysing code rather than reading up functions. I'll test it now. ^^ Thanks a lot!
ProfessorTenebrae #4
Posted 02 March 2014 - 06:39 AM
Um it should work but for some reason I cant get the computer to send any signal through the cables. Like, in any setup on my world. Am I doing something wrong?
Bomb Bloke #5
Posted 02 March 2014 - 08:38 AM
ComputerCraft doesn't support Project Red's bundled cables (apparently they're not "popular" enough, so only MFR's RedNet cables get official support), so the only way to interface with them is via a customised peripheral specifically built for the task (I'm assuming that block between your computer and the wires happens to be an appropriate one?).

It seems there are at least a couple of mods which add such peripherals, and the commands vary a bit, so it's difficult to say exactly how you should deal with yours. Try wrapping it and using the regular setBundledOutput etc functions on it.