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

Airship control panel, function not closing

Started by icecube45, 19 May 2013 - 06:04 PM
icecube45 #1
Posted 19 May 2013 - 08:04 PM
As said in the title, the program still things that the function needs an end at line 30


function menu()
term.clear()
term.setCursorPos(1,1)
print("Airship Control")
print("Options: Left, Right, Back, foward, Up, Down")
print("Choose a Direction:")
direction = read()
if direction == "left" or direction == "Left" then
  left()
end
if direction == "right" or direction == "Right" then
  right()
end
if direction == "foward" or direction == "Foward" then
  foward()
end
if direction == "back" or direction == "Back" then
  back()
end
if direction == "up" or direction == "Up" then
  up()
end
if direction == "down" or direction == "Down" then
  down()
end
end
function left()
print("Press Any Button To Stop")
until os.pullEvent("key") do
  c = colors.combine(c, colors.blue)
  rs.setBundledOutput("back", c)
  os.sleep(1)
  c = colors.subtract(c, colors.blue)
  rs.setBundledOutput("back", c)
end
menu()
end

function right()
print("Press Any Button To Stop")
until os.pullEvent("key") do
  c = colors.combine(c, colors.white)
  rs.setBundledOutput("back", c)
  os.sleep(1)
  c = colors.subtract(c, colors.white)
  rs.setBundledOutput("back", c)
end
menu()
end

function back()
print("Press Any Button To Stop")
until os.pullEvent("key") do
  c = colors.combine(c, colors.lime)
  rs.setBundledOutput("back", c)
  os.sleep(1)
  c = colors.subtract(c, colors.lime)
  rs.setBundledOutput("back", c)
end
  menu()
end
function foward()
print("Press Any Button To Stop")
until os.pullEvent("key") do
  c = colors.combine(c, colors.yellow)
  rs.setBundledOutput("back", c)
  os.sleep(1)
  c = colors.subtract(c, colors.yellow)
  rs.setBundledOutput("back", c)
end
  menu()
end

function up()
print("Press Any Button To Stop")
until os.pullEvent("key") do
  c = colors.combine(c, colors.red)
  rs.setBundledOutput("back", c)
  os.sleep(1)
  c = colors.subtract(c, colors.red)
  rs.setBundledOutput("back", c)
end
menu()
end

function down()
print("Press Any Button To Stop")
until os.pullEvent("key") do
  c = colors.combine(c, colors.orange)
  rs.setBundledOutput("back", c)
  os.sleep(1)
  c = colors.subtract(c, colors.orange)
  rs.setBundledOutput("back", c)
end
menu()
end

menu()
W00dyR #2
Posted 19 May 2013 - 09:06 PM
Instead of

until os.pullEvent("key") do
  c = colors.combine(c, colors.orange)
  rs.setBundledOutput("back", c)
  os.sleep(1)
  c = colors.subtract(c, colors.orange)
  rs.setBundledOutput("back", c)
end

Use


repeat
  c = colors.combine(c, colors.orange)
  rs.setBundledOutput("back", c)
  os.sleep(1)
  c = colors.subtract(c, colors.orange)
  rs.setBundledOutput("back", c)
until os.pullEvent("key")

Check if that works and report in again :P/>

PS: That goes for all the loops you initiate in the functions for different directions
icecube45 #3
Posted 19 May 2013 - 09:23 PM
thank you! it works