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

'end' expected?

Started by bobmarley123456, 19 January 2013 - 08:19 AM
bobmarley123456 #1
Posted 19 January 2013 - 09:19 AM
This code says that 'end' expected at 51


x = yes
y = no
pullEvent = os.pullEventRaw
term.clear()
term.setCursorPos( 1,1)
print "========================="
print "BobMarleyCraftOS Beta 1.1"
print "========================="
print "Password: "
password = read()
pass = "poop"
if password == (pass) then
sleep(2)
print("Welcome")
term.clear()
term.setCursorPos( 1,1 )
print "========================="
print "BobMarleyCraftOS Beta 1.1"
print "========================="
sleep(1)
else
print "Wrong Password"
sleep(1)
term.clear()
term.setCursorPos( 1,1 )
print "========================="
print "BobMarleyCraftOS Beta 1.1"
print "========================="
os.reboot()
print("View Programs")
input = read()
if input =="yes" then
print "-------------------"
print "Avaliable programs:"
print "-------------------"
sleep(1)
print "1.Meltdown"
sleep(1)
print "2.RPG Game"
sleep(1)
print "3.Rock Paper Scissors(RPS)"
sleep(1)
print "4.Other...."
else
print("Thank you for choosing BobMarleyCraftOS")
end           <----------------------------------------------------------------Line 51

Can anyone help?
bobmarley123456 #2
Posted 19 January 2013 - 09:21 AM
I have fixed it now thanks :)/>
OmegaVest #3
Posted 19 January 2013 - 09:23 AM
You are missing an end. You never close the else in the password section, that I can see. That said, I can't really see much without formatting. Hold on.

…..Yup. Missing that end.

Also, do think about formatting. Three spaces when you open an if or a loop, three backspaces when you add an end.


while true do
   for i = 1, 2 do
      if x then
         something
      else
         simething else.
      end
   end
end
Lyqyd #4
Posted 19 January 2013 - 09:27 AM
Three spaces? You suggest indentation, which is great, but the suggest spaced indentation, which is bad enough in itself, but also suggest the abomination of three spaces for indentation? That's just wrong! :P/>

I am mostly joking, but tabs are better in my opinion, and a major benefit is that I can have my tab width be whatever I want and you can have yours be whatever you want (even three… *shudder*).
bobmarley123456 #5
Posted 19 January 2013 - 10:09 AM
This problem came up at line 71


term.clear()
master = ("xXLUKEYBOYXx256")
admin = ("bobmarley123456")
mpass = ("poop")
apass = ("poop")
x = yes
y = no
pullEvent = os.pullEventRaw
term.clear()
term.setCursorPos( 1,1)
print "========================="
print "BobMarleyCraftOS Beta 1.1"
print "========================="
sleep(1)
print("Welcome!")
sleep(3)
write("Username: ")
username = read()
if username == (master) then
sleep(1)
print("Username Found")
sleep(2)
write("Password: ")
  password = read("*")
  if password == (mpass) then
  sleep(0.5)
  print("Prosessing...")
  sleep(4)
  print("correct password")
  sleep(3)
term.clear()
term.setCursorPos( 1,1 )
print "========================="
print "BobMarleyCraftOS Beta 1.1"
print "========================="
sleep(1)
print("View Programs")
input = read()
if input =="yes" then
print "-------------------"
print "Avaliable programs:"
print "-------------------"
sleep(1)
print "1.Meltdown"
sleep(1)
print "2.RPG Game"
sleep(1)
print "3.Rock Paper Scissors(RPS)"
sleep(1)
print "4.Other...."
sleep(1)
print("Thank you for choosing BobMarleyCraftOS")
else
print("Thank you for choosing BobMarleyCraftOS")
end
else
print("Username and password do not match.")
sleep(2)
os.reboot()
end
else
  sleep(1)
  print("User name and password do not match.")
  sleep(2)
  os.reboot()
  end
                               <-----------------------------------------------Line 71
else
sleep(2)
print("User name not found.")
sleep(4)
os.reboot()
end
term.clear()
term.setCursorPos( 1,1 )
print "========================="
print "BobMarleyCraftOS Beta 1.1"
print "========================="
os.reboot()

anyone got any ideas?
KaoS #6
Posted 19 January 2013 - 10:17 AM
you don't need to end your else statements, if you have too many end statements you get that error
bobmarley123456 #7
Posted 19 January 2013 - 10:19 AM
Where should i remove end's
Luanub #8
Posted 19 January 2013 - 10:28 AM
Here's a proper if block, you must have 1 if and 1 end, you can have as many elseif's as you want and only 1 else and it must be the last condition prior to the end

if a == b then
-- do stuff
elseif a == c then
  -- do other stuff
else
  -- nothing else matched so do this
end
remiX #9
Posted 19 January 2013 - 10:29 AM
Look at each else, and remove the end within each else block except for the last one
TheOddByte #10
Posted 19 January 2013 - 10:32 AM
After the else statements as KaoS Mentioned,
And why do you create a new topic everytime you get a new error?
Just Post in one instead of making so many!
And you should really consider putting your codes in spoilers.
How To Do It?
Well Simply type:
Spoiler

[*SPOILER]
This is Going to be printed in the spoiler
Don't use the * when creating a spoiler
[/*SPOILER]
bobmarley123456 #11
Posted 19 January 2013 - 10:36 AM
ok sorry, also i tried removing the end's and it said i needed them and when i put it back it said <eof>
Lyqyd #12
Posted 19 January 2013 - 10:43 AM
Threads merged. Stick to one topic when asking further questions about the same piece of code, please.

Hellkid, just report the topic(s) next time.
TheOddByte #13
Posted 19 January 2013 - 10:46 AM
Threads merged. Stick to one topic when asking further questions about the same piece of code, please.

Hellkid, just report the topic(s) next time.

Sure just want to let him know so he'll listen to me and not keep doing this over and over everytime he get's an error.
bobmarley123456 #14
Posted 19 January 2013 - 10:54 AM
Remember guys could someone please tell me how to fix it please, I tried all the other comments and they didn't work, any more ideas or if possible could you fix it and send me the code?
Lyqyd #15
Posted 19 January 2013 - 11:38 AM
Threads merged. Stick to one topic when asking further questions about the same piece of code, please.

Hellkid, just report the topic(s) next time.

Sure just want to let him know so he'll listen to me and not keep doing this over and over everytime he get's an error.

I understand that, but that is the reason that when I merge the threads, I post why they were merged and what to do in the future. We discourage backseat moderating (even the relatively benign sort you did) for various reasons. :)/>
ChunLing #16
Posted 19 January 2013 - 03:37 PM
Please post your current version of the code and a complete description of the deviations from expected behavior (starting, of course, with error messages).
bobmarley123456 #17
Posted 19 January 2013 - 11:08 PM
error: bios:206: [string "startup"]:74: '<eof>' expected

Code:
Spoiler

term.clear()
master = ("xXLUKEYBOYXx256")
admin = ("bobmarley123456")
mpass = ("poop")
apass = ("poop")
x = yes
y = no
pullEvent = os.pullEventRaw
term.clear()
term.setCursorPos( 1,1)
print "========================="
print "BobMarleyCraftOS Beta 1.1"
print "========================="
sleep(1)
print("Welcome!")
sleep(3)
write("Username: ")
username = read()
if username == (master) then
sleep(1)
print("Username Found")
sleep(2)
write("Password: ")
  password = read("*")
  if password == (mpass) then
  sleep(0.5)
  print("Prosessing...")
  sleep(4)
  print("correct password")
  sleep(3)
term.clear()
term.setCursorPos( 1,1 )
print "========================="
print "BobMarleyCraftOS Beta 1.1"
print "========================="
sleep(1)
print("View Programs")
input = read()
if input =="yes" then
print "-------------------"
print "Avaliable programs:"
print "-------------------"
sleep(1)
print "1.Meltdown"
sleep(1)
print "2.RPG Game"
sleep(1)
print "3.Rock Paper Scissors(RPS)"
sleep(1)
print "4.Other...."
sleep(1)
print("Thank you for choosing BobMarleyCraftOS")
else
print("Thank you for choosing BobMarleyCraftOS")

end
else
print("Username and password do not match.")
sleep(2)
os.reboot()
end
else
  sleep(1)
  print("User name and password do not match.")
  sleep(2)
  os.reboot()
  end
else
sleep(2)
print("User name not found.")
sleep(4)
os.reboot()
end
term.clear()
term.setCursorPos( 1,1 )
print "========================="
print "BobMarleyCraftOS Beta 1.1"
print "========================="
os.reboot()
theoriginalbit #18
Posted 19 January 2013 - 11:11 PM
line 61-72 there is an extra "else end" in there

the <eof> error means that the compiler expects to see the End Of the File, but there is still more code…
TheOddByte #19
Posted 20 January 2013 - 12:29 AM
This would be much easier if you use functions and elseif's
Like this:
Spoiler


function main()
term.clear()
master = ("xXLUKEYBOYXx256")
admin = ("bobmarley123456")
mpass = ("poop")
apass = ("poop")
x = yes
y = no
pullEvent = os.pullEventRaw
term.clear()
term.setCursorPos( 1,1)
print "========================="
print "BobMarleyCraftOS Beta 1.1"
print "========================="
sleep(1)
print("Welcome!")
sleep(3)
write("Username: ")
username = read()
if username == (master) then
sleep(1)
print("Username Found")
sleep(2)
hPass()
elseif username ~= (master) then
sleep(2)
print("User name not found.")
sleep(4)
os.reboot()
end
 end


function hPass()
write("Password: ")
  password = read("*")
  if password == (mpass) then
  sleep(0.5)
  print("Prosessing...")
  sleep(4)
  print("correct password")
  sleep(3)
term.clear()
term.setCursorPos( 1,1 )
print "========================="
print "BobMarleyCraftOS Beta 1.1"
print "========================="
sleep(1)
print("View Programs")
hPrograms()
elseif password ~= (mpass) then
print("Username and password do not match.")
sleep(2)
os.reboot()
end
 end


function hPrograms()
input = read()
if input =="Yes" or input == "yes" then
print "-------------------"
print "Avaliable programs:"
print "-------------------"
sleep(1)
print "1.Meltdown"
sleep(1)
print "2.RPG Game"
sleep(1)
print "3.Rock Paper Scissors(RPS)"
sleep(1)
print "4.Other...."
sleep(1)
print("Thank you for choosing BobMarleyCraftOS")
elseif input == "No" or input == "no" then
print("Thank you for choosing BobMarleyCraftOS") 
else
term.clear()
term.setCursorPos( 1,1 )
print "========================="
print "BobMarleyCraftOS Beta 1.1"
print "========================="
os.reboot()
end
 end

 main()
bobmarley123456 #20
Posted 20 January 2013 - 04:01 AM
Thanks i will try that