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

bios:206: [string "KosOS"]:35: 'end' expected (to close 'if' at line 15)

Started by koslas, 28 July 2012 - 12:39 AM
koslas #1
Posted 28 July 2012 - 02:39 AM
I recently made my own OS called KosOS, It works fine but I recently made a help file for it, This isn't working for some reason though

sorry I don't know how to make spoilers

Here is the code



print ("Welcome to your new Operating System (OS)")
sleep(1)
print ("Would you like to know the new programs on this OS?")
print ("Y/N")
input = read()
if input == "Y" then
print ("KosOS offers a range of new programs.")
print ("The new programs are")
print ("1. Chat")
print ("2. Mail")
print ("We are trying to get more programs for this OS")
print ("Please type what program you would like to know about (number)")
print ("If you would like to leave type 'leave'")
prog = read()
if prog == "1" then
print ("Chat")
print ("The chat program is a way to chat through computers.")
print ("Don't like your Minecraft username?")
print ("We ask you for a name to use.")
print ("With this feature you could choose your real name, or something completely new")
print ("If it's something different others wont reconise you though")
print ("NOTE: You must have a wireless modem")
print ("If you would like to know this again type 'KosOS'")
elseif prog == "2" then
print ("Mail")
print ("This is your E-Mail")
print ("You send and recieve mesages")
print ("When you are sending messages make sure to send it to the computer ID not the persons name")
print ("If you are waiting for mail that has been sent you must Refresh your Email")
print ("Before you send any mail you should change your name for the computer. This will show up as the name for other users")
print ("NOTE: You need a wireless modem")
print ("IMPORTANT: You must go edit pref and change side to what side your wireless modem is on")
else
print ("Invalid entry")
elseif input = "N" then
print ("If you would like this help at anytime just type KosOS")
else
print ("Invalid entry")
end
but I get the error:
bios:206: [string "KosOS"]:35: 'end' expected (to close 'if' at line 15)
Tiin57 #2
Posted 28 July 2012 - 03:08 AM
You need another "end" added on to the end of the file. If you get that message, it's generally good to check that you ended all your if statements.
koslas #3
Posted 28 July 2012 - 03:33 AM
I tried adding a 'end' and 2 'end's but it still doesn't work, any idea?
Luanub #4
Posted 28 July 2012 - 04:04 AM
Use proper code indentation it will help you see where your issue is. You've got some if statement issues. Without knowing the logic of your code I'm not able to give you a corrected code. Here is how if statements should work.


if varA == varB then
   do some stuff
elseif varA == varC then
   do other stuff
else
   do something totally different
end

You also nest if statements within each other just follow the above syntax

if varA == varB then
   do some stuff
   if varC == varD then
	  do this too
   elseif varC == varE then
	  do this as well
   else
	  do nothing
   end
elseif varA == varC then
   do this
else
   do this
end

Each if can only have 1 else and it must be the last part of the statement. It can have as many elseif's as you want, and must end with an end.

Hope this helps.
Lyqyd #5
Posted 28 July 2012 - 04:09 AM
So, the corrected code would look vaguely thus:


print ("Welcome to your new Operating System (OS)")
sleep(1)
print ("Would you like to know the new programs on this OS?")
print ("Y/N")
input = read()
if input == "Y" then
    print ("KosOS offers a range of new programs.")
    print ("The new programs are")
    print ("1. Chat")
    print ("2. Mail")
    print ("We are trying to get more programs for this OS")
    print ("Please type what program you would like to know about (number)")
    print ("If you would like to leave type 'leave'")
    prog = read()
    if prog == "1" then
        print ("Chat")
        print ("The chat program is a way to chat through computers.")
        print ("Don't like your Minecraft username?")
        print ("We ask you for a name to use.")
        print ("With this feature you could choose your real name, or something completely new")
        print ("If it's something different others wont reconise you though")
        print ("NOTE: You must have a wireless modem")
        print ("If you would like to know this again type 'KosOS'")
    elseif prog == "2" then
        print ("Mail")
        print ("This is your E-Mail")
        print ("You send and recieve mesages")
        print ("When you are sending messages make sure to send it to the computer ID not the persons name")
        print ("If you are waiting for mail that has been sent you must Refresh your Email")
        print ("Before you send any mail you should change your name for the computer. This will show up as the name for other users")
        print ("NOTE: You need a wireless modem")
        print ("IMPORTANT: You must go edit pref and change side to what side your wireless modem is on")
    else
        print ("Invalid entry")
    end --Note the additional end here.
elseif input = "N" then
    print ("If you would like this help at anytime just type KosOS")
else
    print ("Invalid entry")
end
koslas #6
Posted 28 July 2012 - 04:43 AM
So, the corrected code would look vaguely thus:


print ("Welcome to your new Operating System (OS)")
sleep(1)
print ("Would you like to know the new programs on this OS?")
print ("Y/N")
input = read()
if input == "Y" then
	print ("KosOS offers a range of new programs.")
	print ("The new programs are")
	print ("1. Chat")
	print ("2. Mail")
	print ("We are trying to get more programs for this OS")
	print ("Please type what program you would like to know about (number)")
	print ("If you would like to leave type 'leave'")
	prog = read()
	if prog == "1" then
		print ("Chat")
		print ("The chat program is a way to chat through computers.")
		print ("Don't like your Minecraft username?")
		print ("We ask you for a name to use.")
		print ("With this feature you could choose your real name, or something completely new")
		print ("If it's something different others wont reconise you though")
		print ("NOTE: You must have a wireless modem")
		print ("If you would like to know this again type 'KosOS'")
	elseif prog == "2" then
		print ("Mail")
		print ("This is your E-Mail")
		print ("You send and recieve mesages")
		print ("When you are sending messages make sure to send it to the computer ID not the persons name")
		print ("If you are waiting for mail that has been sent you must Refresh your Email")
		print ("Before you send any mail you should change your name for the computer. This will show up as the name for other users")
		print ("NOTE: You need a wireless modem")
		print ("IMPORTANT: You must go edit pref and change side to what side your wireless modem is on")
	else
		print ("Invalid entry")
	end --Note the additional end here.
elseif input = "N" then
	print ("If you would like this help at anytime just type KosOS")
else
	print ("Invalid entry")
end

with this lot of code I am getting the error
bios:206 [ string "KosOS"]:36: 'then' expected
Luanub #7
Posted 28 July 2012 - 05:20 AM
Line 36

elseif input = "N" then


change to

elseif input == "N" then -- two ='s to check not 1

koslas #8
Posted 28 July 2012 - 06:34 AM
Line 36

elseif input = "N" then


change to

elseif input == "N" then -- two ='s to check not 1


thanks, never relised it was only one =