Jump to content




Need Help With Elevator Program


  • You cannot reply to this topic
32 replies to this topic

#1 Gomo

  • Members
  • 19 posts

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 & I'm here.

I'd appreciate any help from you guys!

Edited by Gomo, 27 January 2015 - 01:33 PM.


#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

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.computerc...olors_%28API%29

Edited by Bomb Bloke, 27 January 2015 - 01:58 PM.


#3 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

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 by Dragon53535, 27 January 2015 - 02:00 PM.


#4 Gomo

  • Members
  • 19 posts

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 by Gomo, 27 January 2015 - 02:37 PM.


#5 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

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.

#6 Gomo

  • Members
  • 19 posts

Posted 27 January 2015 - 02:43 PM

View PostBomb Bloke, on 27 January 2015 - 02:25 PM, said:

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 by Gomo, 27 January 2015 - 02:54 PM.


#7 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

Posted 27 January 2015 - 09:38 PM

View PostGomo, on 27 January 2015 - 02:43 PM, said:

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

#8 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

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.

#9 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

Posted 27 January 2015 - 11:35 PM

View PostBomb Bloke, on 27 January 2015 - 11:07 PM, said:

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.

#10 Gomo

  • Members
  • 19 posts

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 by Gomo, 28 January 2015 - 07:37 AM.


#11 Gomo

  • Members
  • 19 posts

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!

#12 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

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 by Bomb Bloke, 28 January 2015 - 10:51 AM.


#13 Gomo

  • Members
  • 19 posts

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

View PostGomo, on 28 January 2015 - 07:21 AM, said:


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 by Gomo, 28 January 2015 - 09:18 PM.


#14 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

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?

#15 Gomo

  • Members
  • 19 posts

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)

#16 safetyscissors

  • Members
  • 24 posts

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
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.

#17 Gomo

  • Members
  • 19 posts

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" & "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 by Gomo, 29 January 2015 - 03:23 PM.


#18 Dahknee

  • Members
  • 1,808 posts
  • Location/home/da

Posted 29 January 2015 - 03:06 PM

View PostGomo, on 27 January 2015 - 01:24 PM, said:

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 & I'm here.

I'd appreciate any help from you guys!

Quick question, elevator? a moving one or? Cheers

#19 Gomo

  • Members
  • 19 posts

Posted 29 January 2015 - 06:57 PM

View PostDannySMc, on 29 January 2015 - 03:06 PM, said:

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 by Gomo, 29 January 2015 - 07:01 PM.


#20 Dahknee

  • Members
  • 1,808 posts
  • Location/home/da

Posted 29 January 2015 - 10:17 PM

View PostGomo, on 29 January 2015 - 06:57 PM, said:

View PostDannySMc, on 29 January 2015 - 03:06 PM, said:

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....





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users