Jump to content

Elevator Code Help


Recommended Posts

I recently started using RP frames and want to create an elevator that uses ComputerCraft and RP. I need to know if this code is alright.

os.pullEvent = os.pullEventRaw

print ("Welcome, are you going up or down?")

write ("")

x = io.read()

if x=="up" then

print("Which floor are you going to?")

write()

if x=="1" then

sleep(3)

redstone.setOutput("top", true)

sleep(1)

redstone.setOutput("top", false)

sleep(4)

redstone.setOutput("bottom", true)

sleep(10)

redstone.setOutput("bottom", false)

end

else

if x=="2" then

sleep(3)

redstone.setOutput("top", true)

sleep(2)

redstone.setOutput("top", false)

sleep(4)

redstone.setOutput("bottom", true)

sleep(10)

redstone.setOutput("bottom", false)

end

else

if x=="3" then

sleep(3)

redstone.setOutput("top", true)

sleep(3)

redstone.setOutput("top", false)

sleep(4)

redstone.setOutput("bottom", true)

sleep(10)

redstone.setOutput("bottom", false)

end

else

if x=="4" then

sleep(3)

redstone.setOutput("top", true)

sleep(4)

redstone.setOutput("top", false)

sleep(4)

redstone.setOutput("bottom", true)

sleep(10)

redstone.setOutput("bottom", false)

end

end

sleep(4)

os.shutdown

Link to comment
Share on other sites

Use Code Tags

Instead of os.pullEventRaw use Pull event with Char

Sleeping while the RS signal is on will still only make you advance 1 block, no matter how long you sleep

Use a switch case to define how many blocks you need to elevate (Floor 1 is 5 blocks, floor 2 is 10 etc)

Then use a for to run "rs on, sleep 1, rs off, sleep 1" for that many blocks

After that sleep for 10 seconds then run the for again only in reverse so that the lift goes back down

Some of this is assumptions based off of what info you have given me

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...