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

[Error] elseif giving me a hard time.

Started by krealle, 20 September 2012 - 01:49 PM
krealle #1
Posted 20 September 2012 - 03:49 PM
Hello, so i am trying to make a program where you can turn redstone signals on and off, for controlling various things.

But i am getting this error code

bios:206: [string "control"]:45: '<eof>' expected

Here is a link to the code so you can actually see the problem http://pastebin.com/SbZ7cKeA

I have been trying to fix this issue for about two days now and feel like i could use some help from people that actually know what they are doing.

Thank you.
Mr. Fang #2
Posted 20 September 2012 - 03:52 PM
I don't know anything about elseifs…(Don't facepalm yet)… But I know that when I try to use them, and they fail, I just change then to "if then" and it seems to work out for me.
krealle #3
Posted 20 September 2012 - 04:11 PM
So i would just change it from

elseif input == "red" then
to
if then input == "red" then
Mr. Fang #4
Posted 20 September 2012 - 04:34 PM
Nope you would want it to be

if input == "red" then

That should be it…I suggest testing it out though…I'm not great with this stuff.
Fatal_Exception #5
Posted 20 September 2012 - 04:42 PM
You need to pay more attention to where your 'end's go.

if this == that then
   doThat()
elseif this == theother then
   doTheOther()
else
   WhatDoIDoNow()
end

Notice there's only one 'end', after you've tested all the conditions you're interested in.

I've taken a crack at structuring your code correctly. It's untested, and there seems to be a lot of probably unwanted infinite loops, but I'll leave your logic for you to work out.

Spoiler


local function centerText(text)
  local x,y = term.getSize()
  local x2,y2 = term.getCursorPos()
  term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
  write(text)
end

while true do
  term.clear()
  term.setCursorPos(1,1)
  print("Choose your color!")
  print("Red, Blue, Yellow.")
  input = read()
  print("")

  term.setCursorPos(1,1)

  if input == "red" then
    while true do
      term.clear()
      print("On/Off")
      print("")
      input = read()
      term.setCursorPos(1,1)
      if input == "on" then
        term.clear()
        rs.setBundledOutput("back",colors.red)
        print("Red Activated")
        os.sleep(2)
        term.clear()
        term.setCursorPos(1,1)
      elseif input == "off" then
        term.clear()
        rs.setBundledOutput("back",0)
        print("Red Deactivated")
        os.sleep(2)
        term.clear()
        term.setCursorPos(1,1)
      end
    end
  elseif input == "blue" then
    while true do
      term.clear()
      print("On/Off")
      print("")
      input = read()
      term.setCursorPos(1,1)
      if input == "on" then
        term.clear()
        rs.setBundledOutput("back",colors.blue)
        print("Blue Activated")
        os.sleep(2)
        term.clear()
        term.setCursorPos(1,1)
      elseif input == "off" then
        term.clear()
        rs.setBundledOutput("back",0)
        print("Blue Deactivated")
        os.sleep(2)
        term.clear()
        term.setCursorPos(1,1)
      end
    end
  elseif input == "yellow" then
    term.clear()
    while true do
      term.clear()
      print("On/Off")
      print("")
      input = read()
      term.setCursorPos(1,1)
      if input == "on" then
        term.clear()
        rs.setBundledOutput("back",colors.yellow)
        print("Yellow Activated")
        os.sleep(2)
        term.clear()
        term.setCursorPos(1,1)
      elseif input == "off" then
        term.clear()
        rs.setBundledOutput("back",0)
        print("Yellow Deactivated")
        os.sleep(2)
        term.clear()
        term.setCursorPos(1,1)
      end
    end
  elseif input == "debug" then
    while true do
      term.clear()
      term.setCursorPos(1,1)
      print("Insert Password:")
      term.setCursorPos(17,1)
      input = read("*")
      if input == "bacon" then
        term.clear()
        term.setCursorPos(1,1)
        print("Password correct!")
        os.sleep(1)
        term.clear()
        break
      else
        term.clear()
        term.setCursorPos(1,1)
        print("Password incorrect!")
        sleep(2)
      end
    end
  else  
    print("DA FUQ?!!?")
  end
end

  --term.clear()
  --centerText("What the hell are you on about?")
  --os.sleep(2)
  --end
--end
--end

Edit: Text editor did something weird to my spacing.