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

Need Help With Elevator Program

Started by Gomo, 27 January 2015 - 12:24 PM
Gomo #1
Posted 27 January 2015 - 01:24 PM
Hello guys,

I've been trying to make my own 3 floor elevator program, and yeah.. I'm stuck.

I have 3 floors at different heights, and my elevator runs on carriage engine which moves as long as it has redstone signal powering it. Inside the elevator floor corner is a built in redstone block which sends redstone signal to the either lime, black or yellow wire whenever it reaches on of those 3 floors. On the left side of the computer is bundled cable.

Cable colors:
Red - carriage engine down
Green - carriage engine up
Lime - first floor
Yellow - second floor
black - third floor

And this is what I wrote so far..



print("Press 0 if you'd like to call the elevator.")
print("Select the floor by entering 1,2 or 3.")
input = read()
if input == "0" then
print("Elevator is on the way. Please wait.")
if rs.getBundledInput("left", colors.lime) then
end
if rs.getBundledInput("left". colors.yellow) then
rs.setBundledOutput("left", colors.green, true)
sleep(12)
rs.setBundledOutput("left", colors.green, false)
end
if rs.getBundledInput("left", colors.black) then
rs.setBundledOutout("left", colors.green, true)
sleep(17)
rs.setBundledOutout("left", colors.green, false)
end
elseif input == "1" then
print("Elevator is on this floor.")
elseif input == "2" then
sleep(4)
rs.setBundledOutput("left", colors.red, true)
sleep(12)
rs.setBundledOutput("left", colors.red, false)
os.shutdown()
elseif input == "3" then
sleep(4)
rs.setBundledOutput("left", colors.red, true)
sleep(17)
rs.setBundledOutput("left", colors.red, false)
os.shutdown()
end

else
print("Wrong input, please try again.")
sleep(2)
os.shutdown()
end


Here's what I want in short:

If standing on first floor and I enter "0", I want the program to check which one those 3 wires (either lime, black or yellow) have redstone signal <On> and then depending on that it outputs redstone signal to the carriage engine for either 12 or 17 seconds (if the elevator was on second floor then 12, if third then 17) and if the elevator is on the first floor then it does nothing.
If I'm standing on first floor and I press "2" it should wait 4 seconds for me to enter in the elevator and send redstone signal to the red wire (which is for carriage engine - down) for 12 seconds
If I'm standing on first floor and I press "3" it should wait 4 seconds for me to enter in the elevator and send redstone signal to the red wire (which is for carriage engine - down) for 17 seconds

And I know that I'll need to change timings for second and third floor computer.

There's a lot of things I still don't know about Computercraft, and hence why my program doesn't work &amp; I'm here.

I'd appreciate any help from you guys!
Edited on 27 January 2015 - 12:33 PM
Bomb Bloke #2
Posted 27 January 2015 - 01:56 PM
Instead of this sort of thing:

if rs.getBundledInput("left", colors.lime) then

… you want this sort of thing:

if colors.test(rs.getBundledInput("left"), colors.lime) then

And instead of this sort of thing:

rs.setBundledOutout("left", colors.green, true)

… you want this sort of thing:

rs.setBundledOutput(colors.combine(rs.getBundledInput("left"), colors.green))

And instead of this sort of thing:

rs.setBundledOutput("left", colors.red, false)

… you want this sort of thing:

rs.setBundledOutput(colors.subtract(rs.getBundledInput("left"), colors.red))

http://www.computercraft.info/wiki/Colors_%28API%29
Edited on 27 January 2015 - 12:58 PM
Dragon53535 #3
Posted 27 January 2015 - 01:58 PM
Depending on what version of CC you're on, you may not be able to use the bundled output. If you can, you're doing it wrong though.
setBundledOutput only has two arguments, the side, and the color.

rs.setBundledOutput(side,colors)
If you want to turn off any wire, just set the bundled output to 0

rs.setBundledOutput(side,0)

EDIT: I think i was :ph34r:/>'d, not entirely sure
Edited on 27 January 2015 - 01:00 PM
Gomo #4
Posted 27 January 2015 - 02:12 PM
Replaced it and tried.. didn't work :X

NOTE: decided to switch bundled cable on the back side of the computer


print("Press 0 if you'd like to call the elevator.")
print("Select the floor by entering 1,2 or 3.")
input = read()
if input == "0" then
print("Elevator is on the way. Please wait.")
if colors.test(rs.getBundledInput("back"), colors.lime) then
end
if colors.test(rs.getBundledInput("back"), colors.yellow) then
rs.setBundledOutput(colors.combine(rs.getBundledInput("back"), colors.green))
sleep(12)
rs.setBundledOutput(colors.subtract(rs.getBundledInput("back"), colors.green))
end
if colors.test(rs.getBundledInput("back"), colors.black) then
rs.setBundledOutput(colors.combine(rs.getBundledInput("back"), colors.green))
sleep(17)
rs.setBundledOutput(colors.subtract(rs.getBundledInput("back"), colors.green))
end
elseif input == "1" then
print("Elevator is on this floor.")
elseif input == "2" then
sleep(4)
rs.setBundledOutput(colors.combine(rs.getBundledInput("back"), colors.red))
sleep(12)
rs.setBundledOutput(colors.subtract(rs.getBundledInput("back"), colors.red))
os.shutdown()
elseif input == "3" then
sleep(4)
rs.setBundledOutput(colors.combine(rs.getBundledInput("back"), colors.red))
sleep(17)
rs.setBundledOutput(colors.subtract(rs.getBundledInput("back"), colors.red))
os.shutdown()
end
else
print("Wrong input, please try again.")
sleep(2)
os.shutdown()
end

Getting this error: "bios:336: [string "startup"]:35: '<eof>' expected"
Edited on 27 January 2015 - 01:37 PM
Bomb Bloke #5
Posted 27 January 2015 - 02:25 PM
EOF stands for End Of File. Typically this means you've got more "end" statements than if/while/whatever statements. Indenting your code correctly would make this easier to spot.
Gomo #6
Posted 27 January 2015 - 02:43 PM
EOF stands for End Of File. Typically this means you've got more "end" statements than if/while/whatever statements. Indenting your code correctly would make this easier to spot.

Fixed that part by removing the "end" above "else" command at the end. Now it runs but doesn't seem to output redstone signals to the bundled cables.

Ow and I use CC v1.63
Edited on 27 January 2015 - 01:54 PM
HPWebcamAble #7
Posted 27 January 2015 - 09:38 PM
Ow and I use CC v1.63

I belive these are the first versions that work with CC 1.6's new API

Project Red: 4.5.0 Build #50

MineFactory Reloaded: 2.8.0RC3-591

Older versions won't work with CC 1.6
Bomb Bloke #8
Posted 27 January 2015 - 11:07 PM
Project Red offered support, but it was disabled due to bugs and I haven't heard tell of it being re-enabled. MFR was apparently "never" going to offer support. But things change, and it's good to hear that bundled cable functionality is starting to come back (in force!)… though I see both those versions you listed are for MC 1.7.10, and so they're still no good for CC 1.63 (which is for MC 1.6.4).

Last I heard, Ender IO's redstone conduits work, but I'm assuming that also only applies to a MC 1.7.10 build.

If you want bundled cable support under MC 1.6.4, then as far as I'm aware you'd need to go back to CC 1.58 (which supports MFR's rednet cables). After that build, Dan decided to stop supporting cables from other mods, and instead opted to rely on other mod developers to provide the support from their end.
HPWebcamAble #9
Posted 27 January 2015 - 11:35 PM
I see both those versions you listed are for MC 1.7.10, and so they're still no good for CC 1.63 (which is for MC 1.6.4).

Exactly. This was a huge problem until CC updated to 1.7.10.
Gomo #10
Posted 28 January 2015 - 07:21 AM
Well… if that's the case, I guess I'll have to use normal alloy wire branched of the bundled cable on different sides of the computer.

Thanks for your help guys!

EDIT:

- http://i.imgur.com/9K91qJg.png
- http://i.imgur.com/tx1Qhnu.png
- http://i.imgur.com/OCdcpbx.png
Edited on 28 January 2015 - 06:37 AM
Gomo #11
Posted 28 January 2015 - 09:48 AM
Second attempt with bundled cable. (Tested this guys code -> http://pastebin.com/GkqvwZ4r .. and it works, which means mine should as well)


print("Press 0 if you'd like to call the elevator.")
print("Select the floor by entering 1,2 or 3.")
input = read()
if input == "0" then
print("Elevator is on the way. Please wait.")
if rs.testBundledInput("back",colors.lime) == true then
print("Elevator is already on this floor.")
sleep(2)
end
if rs.testBundledInput("back",colors.yellow) == true then
rs.setBundledInput("back",colors.green) == true
sleep(12)
rs.setBundledInput("back",colors.green) == false
end
if rs.testBundledInput("back",colors.black) == true then
rs.setBundledInput("back",colors.green) == true
sleep(17)
rs.setBundledInput("back",colors.black) == false
end
elseif input == "1" then
print("Elevator is on this floor.")
elseif input == "2" then
sleep(4)
rs.setBundledInput("back",colors.red) == true
sleep(12)
rs.setBundledInput("back",colors.red) == false
os.shutdown()
elseif input == "3" then
sleep(4)
rs.setBundledInput("back",colors.red) == true
sleep(17)
rs.setBundledInput("back",colors.red) == false
os.shutdown()
else
print("Wrong input, please try again.")
sleep(2)
os.shutdown()
end

it's just that I have error in my code and I'm unable to fix it due to my lack of CC knowledge. So please, could somebody take a look at it and fix the mistakes :/ I'd really appreciate it!
Bomb Bloke #12
Posted 28 January 2015 - 10:50 AM
print("Press 0 if you'd like to call the elevator.")
print("Select the floor by entering 1,2 or 3.")
input = read()
if input == "0" then
	print("Elevator is on the way. Please wait.")
	if rs.testBundledInput("back",colors.lime) then  -- "If" statements already check if a given condition is true; checking if something is true is true is redundant.
		print("Elevator is already on this floor.")
		sleep(2)
	end
	if rs.testBundledInput("back",colors.yellow) then
		rs.setBundledOutput("back",colors.green)  -- You can't set your "in"put.
		sleep(12)
		rs.setBundledOutput("back",0)  -- Either use the colours API to subtract the colur value, or use 0 for no colours.
	end
	if rs.testBundledInput("back",colors.black) then
		rs.setBundledOutput("back",colors.green)  -- You can't set the output of a function to something with an equals sign.
		sleep(17)
		rs.setBundledOutput("back",colors.black)  -- Speaking of which, == means "is equal to". For assigning values, use a single =.
	end
elseif input == "1" then
	print("Elevator is on this floor.")
elseif input == "2" then
	sleep(4)
	rs.setBundledOutput("back",colors.red)
	sleep(12)
	rs.setBundledOutput("back",0)
	os.shutdown()
elseif input == "3" then
	sleep(4)
	rs.setBundledOutput("back",colors.red)
	sleep(17)
	rs.setBundledOutput("back",0)
	os.shutdown()
else
	print("Wrong input, please try again.")
	sleep(2)
	os.shutdown()
end

At some point, you're going to want to learn how to create loops - chunks of code that repeat their instructions over and over. Take a read of this.
Edited on 28 January 2015 - 09:51 AM
Gomo #13
Posted 28 January 2015 - 09:15 PM
What do I have to fix here? I'm trying to make it work with just normal wires instead of the bundled cable



print("Press 0 if you'd like to call the elevator.")
print("Select the floor by entering 1,2 or 3.")
input = read()
if input == "0" then
while true do
print("Elevator is on the way. Please wait.")
if os.pullEvent("redstone")
while rs.getInput("top") do
print("Elevator is already on this floor.")
sleep(2)
end
os.shutdown()
elseif os.pullEvent("redstone")
while rs.getInput("back") do
rs.setOutput("right",true)
sleep(12)
rs.setOutput("right",false)
end
os.shutdown()
elseif os.pullEvent("redstone")
while rs.getInput("bottom") do
rs.setOutput("right",true)
sleep(17)
rs.setOutput("right",false)
end
os.shutdown()
elseif input == "1" then
print("Elevator is on this floor.")
sleep(2)
os.shutdown()
elseif input == "2" then
sleep(4)
rs.setOutput("left", true)
sleep(12)
rs.setOutput("left", false)
os.shutdown()
elseif input == "3" then
sleep(4)
rs.setOutput("left", true)
sleep(17)
rs.setOutput("left", false)
os.shutdown()
else
print("Wrong input, please try again.")
sleep(2)
os.shutdown()
end

Left - Elevator down
Right - Elevator up
Top - Floor 1
Back - Floor 2
Bottom - Floor 3

I apologize for annoying you guys, I'm just trying to learn Computercraft, and so far it's not really good the way I want it to go.
Edited on 28 January 2015 - 08:18 PM
Bomb Bloke #14
Posted 28 January 2015 - 11:15 PM
while rs.getInput("top") do
print("Elevator is already on this floor.")
sleep(2)
end

Er, exactly when is that top input going to change? What sets it in the first place?
Gomo #15
Posted 29 January 2015 - 07:11 AM
Each floor has a different wire color which gets activated when elevator stops on that floor. (lime, yellow, black). So, lets say Top = lime, Back - yellow, Bottom = Black. Each floor will need to have tiny bit different program. And left and right sides of the computer are for elevator up and down. (I wrote the program assuming that the elvator was on first floor)
safetyscissors #16
Posted 29 January 2015 - 11:03 AM
What i think you need is some functions. had some difficultly following what your program was doing.
You have a pretty good first attempt. missing a then on line 7 and the while loops/os.pullEvent/os.shutdowns are used a little oddly.

I might suggest trying to package some stuff into reusable functions. below is an example of your program refactored.

Spoiler

--# must have at least one input
local function findElevator()
	if rs.getInput("top") then return 1; end
	if rs.getInput("back") then return 2; end
	if rs.getInput("bottom") then return 3; end
end

--# moves the elevator
local function moveElevator(elevatorFloor, destFloor)
	local delays = {0,12,17}

	--# get delay time.
	local delayTime = delays[elevatorFloor] - delays[destFloor]
	if destFloor > elevatorFloor then
		delayTime = delays[destFloor] - delays[elevatorFloor]
	end

	--# get signalSide. if elevator is higher than dest go down,
	local signalSide = "left" --# go down
	if destFloor < elevatorFloor then
		direction = "right" --# go down
	end

	--#turns on, sleeps, turns off.
	rs.setOutput(signalSide, true)
	sleep(delayTime)
	rs.setOutput(signalSide, false)
end

--# config floor and instructions
local thisTerminalsFloor = 1
print("instructions")
local input = tonumber(read())

--# call elevator to this floor when any input is given
local elevatorPos = findElevator()
moveElevator(elevatorPos, thisTerminalsFloor)

--# i assume the pause is for boarding,
sleep(4)

--# go to floor if input is valid
if input>=1 and input<=3 then
	moveElevator(thisTerminalsFloor, input)
end

--# end program
sleep(2)
os.shutdown()
not tested, but should be able to use the same script on all your floors by changing the thisTerminalsFloor value.
commenting intentions, using space indents, and using locals at the least, helps me to see my mistakes faster.
Gomo #17
Posted 29 January 2015 - 02:38 PM
Thank you for your effort, it does work expect the elevator sometimes goes down instead of up. Trying to figure out what's wrong in this part:


		--# get signalSide. if elevator is higher than dest go down,
		local signalSide = "left" --# go down
		if destFloor < elevatorFloor then
				direction = "right" --# go down
		end

Probably something with the "greater" &amp; "smaller" symbols, because floor 1 is the top floor, 2 is the middle and 3 is the lowest. ("basment elevator")

Edit: Tried switching em up, still doesn't work the way it should. Also, I think there should be a line for adding up delay from 2 floors, example -> when the elevator is on the third floor and you're on the first, you press 1 and it should add 12+17 and go up for 29 seconds. Because otherwise you have to press "1" twice, once for it go reach second floor, and the again so it gets to floor 1.
Edited on 29 January 2015 - 02:23 PM
DannySMc #18
Posted 29 January 2015 - 03:06 PM
Hello guys,

I've been trying to make my own 3 floor elevator program, and yeah.. I'm stuck.

I have 3 floors at different heights, and my elevator runs on carriage engine which moves as long as it has redstone signal powering it. Inside the elevator floor corner is a built in redstone block which sends redstone signal to the either lime, black or yellow wire whenever it reaches on of those 3 floors. On the left side of the computer is bundled cable.

Cable colors:
Red - carriage engine down
Green - carriage engine up
Lime - first floor
Yellow - second floor
black - third floor

And this is what I wrote so far..



print("Press 0 if you'd like to call the elevator.")
print("Select the floor by entering 1,2 or 3.")
input = read()
if input == "0" then
print("Elevator is on the way. Please wait.")
if rs.getBundledInput("left", colors.lime) then
end
if rs.getBundledInput("left". colors.yellow) then
rs.setBundledOutput("left", colors.green, true)
sleep(12)
rs.setBundledOutput("left", colors.green, false)
end
if rs.getBundledInput("left", colors.black) then
rs.setBundledOutout("left", colors.green, true)
sleep(17)
rs.setBundledOutout("left", colors.green, false)
end
elseif input == "1" then
print("Elevator is on this floor.")
elseif input == "2" then
sleep(4)
rs.setBundledOutput("left", colors.red, true)
sleep(12)
rs.setBundledOutput("left", colors.red, false)
os.shutdown()
elseif input == "3" then
sleep(4)
rs.setBundledOutput("left", colors.red, true)
sleep(17)
rs.setBundledOutput("left", colors.red, false)
os.shutdown()
end

else
print("Wrong input, please try again.")
sleep(2)
os.shutdown()
end


Here's what I want in short:

If standing on first floor and I enter "0", I want the program to check which one those 3 wires (either lime, black or yellow) have redstone signal <On> and then depending on that it outputs redstone signal to the carriage engine for either 12 or 17 seconds (if the elevator was on second floor then 12, if third then 17) and if the elevator is on the first floor then it does nothing.
If I'm standing on first floor and I press "2" it should wait 4 seconds for me to enter in the elevator and send redstone signal to the red wire (which is for carriage engine - down) for 12 seconds
If I'm standing on first floor and I press "3" it should wait 4 seconds for me to enter in the elevator and send redstone signal to the red wire (which is for carriage engine - down) for 17 seconds

And I know that I'll need to change timings for second and third floor computer.

There's a lot of things I still don't know about Computercraft, and hence why my program doesn't work &amp; I'm here.

I'd appreciate any help from you guys!

Quick question, elevator? a moving one or? Cheers
Gomo #19
Posted 29 January 2015 - 06:57 PM
Quick question, elevator? a moving one or? Cheers

Yeah. A bit silly question.. that's what elevator usually does, it moves =) … well, mine is atm a bit disoriented but yeah xD
Edited on 29 January 2015 - 06:01 PM
DannySMc #20
Posted 29 January 2015 - 10:17 PM
Quick question, elevator? a moving one or? Cheers

Yeah. A bit silly question.. that's what elevator usually does, it moves =) … well, mine is atm a bit disoriented but yeah xD

Not a silly question at all… The only mod I know of with an elevator is Pneumaticraft, I was asking what mod it was….
Gomo #21
Posted 29 January 2015 - 10:22 PM
Not a silly question at all… The only mod I know of with an elevator is Pneumaticraft, I was asking what mod it was….

If you asked about mod I would've answered, it's "Remain in motion" mod.
HPWebcamAble #22
Posted 30 January 2015 - 01:42 AM
Here&amp;amp;#39;s what I want in short:

If standing on first floor and I enter "0", I want the program to check which one those 3 wires (either lime, black or yellow) have redstone signal &amp;amp;lt;On&amp;amp;gt; and then depending on that it outputs redstone signal to the carriage engine for either 12 or 17 seconds (if the elevator was on second floor then 12, if third then 17) and if the elevator is on the first floor then it does nothing.
If I&amp;amp;#39;m standing on first floor and I press "2" it should wait 4 seconds for me to enter in the elevator and send redstone signal to the red wire (which is for carriage engine - down) for 12 seconds
If I&amp;amp;#39;m standing on first floor and I press "3" it should wait 4 seconds for me to enter in the elevator and send redstone signal to the red wire (which is for carriage engine - down) for 17 seconds

And I know that I&amp;amp;#39;ll need to change timings for second and third floor computer.

There&amp;amp;#39;s a lot of things I still don&amp;amp;#39;t know about Computercraft, and hence why my program doesn&amp;amp;#39;t work &amp;amp;amp; I&amp;amp;#39;m here.

I&amp;amp;#39;d appreciate any help from you guys!
apostrophes turned into &amp;amp;#39; ?

Personally, I would just 1 computer, and have a single Advanced CC monitor at each floor, connected to the computer with wired network cable.
This would REALLY simplify the code, since you only have 1 computer to worry about.

Each monitor could display the current floor and have a button to call the elevator.

If you are hesitant to try this because you don't know how to use modems or monitors, check out the wikis and ask any questions here.
(http://computercraft...Modem_%28API%29,http://computercraft...dvanced_Monitor)

Just my opinion :)/>
Edited on 30 January 2015 - 01:02 AM
Gomo #23
Posted 01 February 2015 - 08:36 AM
Anyone? :/
Bomb Bloke #24
Posted 01 February 2015 - 09:34 AM
Edit: Tried switching em up, still doesn't work the way it should. Also, I think there should be a line for adding up delay from 2 floors, example -> when the elevator is on the third floor and you're on the first, you press 1 and it should add 12+17 and go up for 29 seconds. Because otherwise you have to press "1" twice, once for it go reach second floor, and the again so it gets to floor 1.

In this table here:

local delays = {0,12,17}

… safetyscissors is assuming that each value stands for the amount of time it takes to get from floor 1 to the floor represented by the respective index. That is to say, floor 1 to floor 3 is 17 seconds. If you're saying it takes 12 seconds to get from floor 1 to floor 2, and 29 seconds to go from floor 1 to floor 3, then the table should be:

local delays = {0,12,29}

Note that these numbers "should" work even if the script isn't running on a system at floor 1, due to maths he's using (although, that could've been simplified with a math.abs() call…).

Personally I'd consider throwing in a check so that the script doesn't do anything if asked to go to the floor you're already at, and instead of relying on sleep timers, I'd stick with redstone events. A rehash of safetyscissors' script:

Spoiler
local thisTerminalsFloor = 1

local function findElevator()
        if rs.getInput("top") then return 1 end     -- Elevator at floor 1.
        if rs.getInput("back") then return 2 end    -- Elevator at floor 2.
        if rs.getInput("bottom") then return 3 end  -- Elevator at floor 3.

        -- If none of the above is true, elevator is at an unknown position (maybe stuck partway). Send it upwards:
	print("Can't determine lift location.")	
	rs.setOutput("right", true)
	os.pullEvent("redstone")
	print("Got possible lift signal; rechecking...")
	rs.setOutput("right", false)
	return findElevator()
end

--# moves the elevator
local function moveElevator(elevatorFloor, destFloor)
        if elevatorFloor ~= destFloor then
        	print("Moving from floor "..tostring(elevatorFloor).." to floor "..tostring(destFloor).."...")
        	
		--# get signalSide. This assumes "right" is to go up, and "left" is to go down.
		local signalSide = destFloor < elevatorFloor and "right" or "left"

		--#turns on, pauses, turns off.
		repeat
			rs.setOutput(signalSide, true)
			os.pullEvent("redstone")
			rs.setOutput(signalSide, false)
		until findElevator() == destFloor
        end
end

local input
while (not input) or input < 1 or input > 3 do
	print("Enter target floor (1 - 3):")
	input = tonumber(read())
end

--# call elevator to this floor
moveElevator(findElevator(), thisTerminalsFloor)

--# i assume the pause is for boarding,
print("Please board.")
sleep(4)

--# go to floor
moveElevator(thisTerminalsFloor, input)

--# end program
print("Operation complete.")
sleep(2)
os.shutdown()
Gomo #25
Posted 01 February 2015 - 10:49 AM
There's something wrong, after I pressed "2" for second floor, the elevator started going up and down. 4 evah xd (1 block down -> 1 block up) &amp; spams "Can't determine lift location", "Got possible lift signal: rechecking…"
Edited on 01 February 2015 - 09:50 AM
Bomb Bloke #26
Posted 01 February 2015 - 11:20 AM
Check your wiring. The cables must supply an input to the top when (and only when) the elevator is at floor 1, an input to the back at floor 2, and so on. The lift must only be able to go upwards when the computer outputs a signal to the right, and should not move at all when that signal is removed.

If in doubt, go to the Lua command prompt and enter in the likes of rs.getInput("top") or rs.setOutput("right",true) manually so that you can track what's going on.
Gomo #27
Posted 01 February 2015 - 11:34 AM
Check your wiring. The cables must supply an input to the top when (and only when) the elevator is at floor 1, an input to the back at floor 2, and so on. The lift must only be able to go upwards when the computer outputs a signal to the right, and should not move at all when that signal is removed.

If in doubt, go to the Lua command prompt and enter in the likes of rs.getInput("top") or rs.setOutput("right",true) manually so that you can track what's going on.

I pasted your code directly into the computer (so I don't think that there's spelling mistakes).

- http://i.imgur.com/39rbjoc.png
- http://i.imgur.com/ONUI5YL.png
- http://i.imgur.com/nO4Epa2.png
Edited on 01 February 2015 - 10:35 AM
Bomb Bloke #28
Posted 02 February 2015 - 10:51 AM
Yep, great, but I'm asking you to forget about the script for the moment and actually clarify how the elevator deals with redstone - in terms of how it sends and receives singles. Don't just explain what you "think" it does, or what you "want" it to do - enter the Lua prompt on your system, and manually check &amp; set some states to find out for sure how it's actually acting.

Currently it sounds like simply toggling the right-hand side redstone output on the computer on and off is enough to make the elevator go up as well as down. That doesn't sound to me to be the way you're wanting it to function.
Gomo #29
Posted 02 February 2015 - 02:58 PM
Yep, great, but I'm asking you to forget about the script for the moment and actually clarify how the elevator deals with redstone - in terms of how it sends and receives singles. Don't just explain what you "think" it does, or what you "want" it to do - enter the Lua prompt on your system, and manually check &amp; set some states to find out for sure how it's actually acting.

Currently it sounds like simply toggling the right-hand side redstone output on the computer on and off is enough to make the elevator go up as well as down. That doesn't sound to me to be the way you're wanting it to function.

Elevator setup:

I use "Remain in motion" mod for the elevator (carriage engine). This engine moves in the direction opposite from which it received redstone signal (example: if it receives RS signal from the top, it'll move the elevator down - NOTE: carriage engine has two "modes", 1. which makes it move only 1 block when RS signal is received even if it stays on, and 2.nd "mode" which makes it turned on/move all the time if the RS is <on>) -> http://i.imgur.com/xklkxDa.png

Each floor has a different wire color which is used for the lights as well as the elevator control. -> http://i.imgur.com/I0MIiER.png (picture of the 2.nd floor - yellow wire) [green light is on because the elevator is on first floor]. The reason why those lights/wires receive redstone signal is because the elevator platform has a redstone block in it's corner -> http://i.imgur.com/ONUI5YL.png

And this is how all the wires are connected to the computer -> http://i.imgur.com/nO4Epa2.png (LEFT - RED, RIGHT - GREEN, TOP - LIME, BACK - YELLOW, BOTTOM - BLACK)

From the first (top) floor to the second (middle) it takes ~ 12 seconds. And from the first to the third, it takes ~ 29 seconds. From second to the third it takes 17 seconds.

Also, there should be ~ 4-6 seconds of "delay" for boarding.

I hope this explains it.
Edited on 02 February 2015 - 02:23 PM
Bomb Bloke #30
Posted 03 February 2015 - 11:11 PM
Concerning the carriage engine, how do the two wires that're connected to it stay connected once it starts moving?
Gomo #31
Posted 04 February 2015 - 07:32 AM
Concerning the carriage engine, how do the two wires that're connected to it stay connected once it starts moving?

It's a bit hard to notice because it's covered with *basalt brick covers* (on the left) -> http://i.imgur.com/I0MIiER.png -> you can see vertical *framed bundled cable* going all the way down. This way, carriage engine is connected with the computer at all times (everything works fine, it's just that there's some error in the code)
Edited on 04 February 2015 - 06:33 AM
Bomb Bloke #32
Posted 04 February 2015 - 11:55 AM
Yeah, I see it now - if you try to send the lift down, the floor location finding function would start trying to bring it back up again once it heads off after boarding.

This should sort it out:

Spoiler
local thisTerminalsFloor = 1

rs.setOutput("left", false)
rs.setOutput("right", false)

while rs.getInput("left") or rs.getInput("right") do
	print("Appears lift is already in use. Please wait...")
	os.pullEvent("redstone")
	sleep(1)
end

local function findElevator()
        if rs.getInput("top") then return 1 end     -- Elevator at floor 1.
        if rs.getInput("back") then return 2 end    -- Elevator at floor 2.
        if rs.getInput("bottom") then return 3 end  -- Elevator at floor 3.
	return false
end

local function moveElevator(elevatorFloor, destFloor)
        if elevatorFloor ~= destFloor then
                print("Moving from floor "..tostring(elevatorFloor).." to floor "..tostring(destFloor).."...")

                local signalSide = destFloor < elevatorFloor and "right" or "left"

                repeat
                        rs.setOutput(signalSide, true)
                        os.pullEvent("redstone")
                        rs.setOutput(signalSide, false)
                until findElevator() == destFloor
        end
end

local input
while (not input) or input < 1 or input > 3 do
        print("Enter target floor (1 - 3):")
        input = tonumber(read())
end

local currentFloor = findElevator()
if not currentFloor then
	print("Can't determine lift location.") 
	repeat
		rs.setOutput("right", true)
		os.pullEvent("redstone")
		print("Got possible lift signal; rechecking...")
		rs.setOutput("right", false)
		currentFloor = findElevator()
	until currentFloor
end

moveElevator(currentFloor, thisTerminalsFloor)

print("Please board.")
sleep(4)

moveElevator(thisTerminalsFloor, input)

print("Operation complete.")
sleep(2)
os.shutdown()
Edited on 04 February 2015 - 10:59 AM
Gomo #33
Posted 04 February 2015 - 05:30 PM
Yeah, I see it now - if you try to send the lift down, the floor location finding function would start trying to bring it back up again once it heads off after boarding.

This should sort it out:

Spoiler
local thisTerminalsFloor = 1

rs.setOutput("left", false)
rs.setOutput("right", false)

while rs.getInput("left") or rs.getInput("right") do
	print("Appears lift is already in use. Please wait...")
	os.pullEvent("redstone")
	sleep(1)
end

local function findElevator()
		if rs.getInput("top") then return 1 end	 -- Elevator at floor 1.
		if rs.getInput("back") then return 2 end	-- Elevator at floor 2.
		if rs.getInput("bottom") then return 3 end  -- Elevator at floor 3.
	return false
end

local function moveElevator(elevatorFloor, destFloor)
		if elevatorFloor ~= destFloor then
				print("Moving from floor "..tostring(elevatorFloor).." to floor "..tostring(destFloor).."...")

				local signalSide = destFloor < elevatorFloor and "right" or "left"

				repeat
						rs.setOutput(signalSide, true)
						os.pullEvent("redstone")
						rs.setOutput(signalSide, false)
				until findElevator() == destFloor
		end
end

local input
while (not input) or input < 1 or input > 3 do
		print("Enter target floor (1 - 3):")
		input = tonumber(read())
end

local currentFloor = findElevator()
if not currentFloor then
	print("Can't determine lift location.")
	repeat
		rs.setOutput("right", true)
		os.pullEvent("redstone")
		print("Got possible lift signal; rechecking...")
		rs.setOutput("right", false)
		currentFloor = findElevator()
	until currentFloor
end

moveElevator(currentFloor, thisTerminalsFloor)

print("Please board.")
sleep(4)

moveElevator(thisTerminalsFloor, input)

print("Operation complete.")
sleep(2)
os.shutdown()

Thank you very much for your time &amp; effort. It works now. I appreciate your help! And I'm also sure other people who are trying to build an elevator are going to be thankful for this.