Jump to content




Problems with everything within a loop


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

#1 Hydrotronics

  • Members
  • 131 posts
  • LocationThe hall of 1000 monkeys and only 1 typewriter

Posted 07 November 2015 - 11:34 PM

Pastebin: http://pastebin.com/E2qm6s5r

So, i am making myself an OS and i have run into a problem here:

whenever I run this program, it wants an end on line 32, but when i place an end there, it says "eof expected" on line 33! and that's an elseif statement! This is really aggrovating me and i just cannot get my head around it!

Please Explain why it is doing this!

Many Thanks, Hydro

#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 07 November 2015 - 11:49 PM

I went through your code, properly indented it, and added comments where I know something is wrong. I don't know how you intend / intended to nest the various if/elseif statements, so you'll have to deal with this yourself.

Spoiler


#3 Lupus590

  • Members
  • 2,028 posts
  • LocationUK

Posted 07 November 2015 - 11:52 PM

elseif act as an end for the prior if

remove the ends on lines 31,39,55

edit: :ph34r: 'd

Edited by Lupus590, 07 November 2015 - 11:53 PM.


#4 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 07 November 2015 - 11:58 PM

View PostLupus590, on 07 November 2015 - 11:52 PM, said:

elseif act as an end for the prior if

No, it doesn't. You still need the end, but you don't need an end for each if / elseif / else. You need 1 end per conditional.

#5 Hydrotronics

  • Members
  • 131 posts
  • LocationThe hall of 1000 monkeys and only 1 typewriter

Posted 07 November 2015 - 11:58 PM

So i have done some editing and now it's requesting an end to the while statement at line 54! then when i put the end in it does the same thing.
Pastebin

so basically it's just gone down :P

Edited by Hydrotronics, 07 November 2015 - 11:59 PM.


#6 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 08 November 2015 - 12:04 AM

There's a problem at the bottom, but I'm not exactly sure what you want it to do. I've indented it properly (PLEASE indent properly, it makes finding these problems so much easier).

sid = 0

function clear()
  term.clear()
  term.setCursorPos(1,1)
end

function menu(id, text)
  if sid == id then
    write"> "
  else
    write"| "
  end
  print(text)
end

while true do
  clear()
  menu(0, "Desktop")
  menu(1, "Create/Edit Program")
  menu(2, "Console")
  menu(3, "Shutdown")
  event, key = os.pullEvent("key")
  if key == 200 then
    print(sid)
    if sid > 0 then
      sid = sid - 1
    else
      sid = sid + 3
    end
  elseif key == 208 then
    print(sid)
    if sid < 3 then
      sid = sid + 1
    else
      sid = sid - 3
    end
  elseif key == 28 then
    if sid == 0 then
      break
    end
    shell.run(".desktop")
  elseif sid == 1 then
    term.clear()
    term.setCursorPos(1,1)
    print"Enter Name Of File:"
    write""
    input = read()
    shell.run("edit "..input)
  elseif sid == 2 then
    break
  end
  shell.run(".Console")
  --#NO IF STATEMENT OPEN FOR THIS ELSEIF
  elseif sid == 3 then
    term.clear()
    term.setCursorPos(10,9)
    print"Shutting Down..."
    sleep(1)
    os.shutdown()
  end
end

Edited by KingofGamesYami, 08 November 2015 - 12:05 AM.


#7 Hydrotronics

  • Members
  • 131 posts
  • LocationThe hall of 1000 monkeys and only 1 typewriter

Posted 08 November 2015 - 12:16 AM

Ok, I removed the end blocking the elseif, and now it wants an end to end the if at line 24! and it want's it at line 52
Code

Edit: Also, i think i indented it properly this time XD

Edited by Hydrotronics, 08 November 2015 - 12:18 AM.


#8 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 08 November 2015 - 12:20 AM

Spoiler


#9 Hydrotronics

  • Members
  • 131 posts
  • LocationThe hall of 1000 monkeys and only 1 typewriter

Posted 08 November 2015 - 12:24 AM

Thank you! you were correct with the breaks, I am new to those. And also i did need the 3rd end, to clsoe the while statement all together

#10 Lupus590

  • Members
  • 2,028 posts
  • LocationUK

Posted 08 November 2015 - 12:41 AM

View PostKingofGamesYami, on 07 November 2015 - 11:58 PM, said:

View PostLupus590, on 07 November 2015 - 11:52 PM, said:

elseif act as an end for the prior if

No, it doesn't. You still need the end, but you don't need an end for each if / elseif / else. You need 1 end per conditional.

that's what I meant, sorry if I wasn't clear





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users