input == (Shutdown) then -- Error is here print ("Shutting down") sleep(1) os.shutdown()So, YEah. :I
1
= Expected and I have tried almost anything
Started by 88theturbo, Mar 28 2013 02:28 PM
16 replies to this topic
#1
Posted 28 March 2013 - 02:28 PM
So, When I try to code a menu a part of the code if having a problem. here is the snippet from the code that isnt working...
#2
Posted 28 March 2013 - 02:29 PM
Never mind about that. Fixed it. :/ Found out that I need a 'if' There.
#3
Posted 28 March 2013 - 02:32 PM
This has multiple problems
first where it says input == (Shutdown) it is supposed to be io.read() == "Shutdown"
Secondly there must be an if.
third there must be a end
putting this all together makes
first where it says input == (Shutdown) it is supposed to be io.read() == "Shutdown"
Secondly there must be an if.
third there must be a end
putting this all together makes
if io.read == "Shutdown" then -- Error is here print ("Shutting down") sleep(1) os.shutdown() endEDIT: You also need to put an end and some other things
#4
Posted 28 March 2013 - 04:02 PM
EDIT: Working on that now.
EDIT 2: Hmm, When I try that exact code, I get-
Bios:337: [string "menu2" ]:32: 'end' expected (to close if at line 21)
at line 21 my code is
EDIT 2: Hmm, When I try that exact code, I get-
Bios:337: [string "menu2" ]:32: 'end' expected (to close if at line 21)
at line 21 my code is
if io.read() == pass1 then term.clear() term.setCursorPos(1,1) -- Yadda yadda yaddaand at line 32 my code is
--31: end --32: ... --the 31 and 32 arent there, and at line 32 my code is empty, which has a end right before it.
#5
Posted 28 March 2013 - 09:07 PM
change io.read to read()
edit: nevermind, you fixed it in your code. But using io.read() instead of read() has no difference, other than it looks ugly and it's longer to type
Can you post your whole code with the error ._.
edit: nevermind, you fixed it in your code. But using io.read() instead of read() has no difference, other than it looks ugly and it's longer to type
Can you post your whole code with the error ._.
#6
Posted 29 March 2013 - 04:07 AM
Ok. Here it is.
bios:337: [string 'menu2'] :32: 'end' expected (to close if at line 17)
Hope you can help...
function newMenu() --tabbed once term.clear() term.setCursorPos(1,1) print ("Select One") --this is where the selections start function selection() term.setCursorPos(10,10) print [[Login Shutdown]] if input == "Login" then -- Tabbed twice term.clear() term.setCursorPos(1,1) pass1 = Colton pass2 = Bacon print ("Username:") input = read("*") if io.read() == to pass1 then term.clear() term.setCursorPos(1,1) print ("Password:") if io.read() = pass2 then term.clear() term.setCursorPos(1,1) end if io.read() == "Shutdown" then --from here it is tabbed 3 print ("Shutting Down...") sleep(1) os.shutdown()So, the error I get is:
bios:337: [string 'menu2'] :32: 'end' expected (to close if at line 17)
Hope you can help...
#7
Posted 29 March 2013 - 04:25 AM
88theturbo, on 29 March 2013 - 04:07 AM, said:
Ok. Here it is.
bios:337: [string 'menu2'] :32: 'end' expected (to close if at line 17)
Hope you can help...
function newMenu() --tabbed once term.clear() term.setCursorPos(1,1) print ("Select One") --this is where the selections start function selection() term.setCursorPos(10,10) print [[Login Shutdown]] if input == "Login" then -- input is not defined yet should be input = read() before term.clear() term.setCursorPos(1,1) pass1 = Colton pass2 = Bacon print ("Username:") input = read("*") if io.read() == to pass1 then. --what is the "to" for i dont think this is correct term.clear() term.setCursorPos(1,1) print ("Password:") if io.read() = pass2 then -- this is causing the error should be if read() == pass2 term.clear() term.setCursorPos(1,1) end if io.read() == "Shutdown" then --from here it is tabbed 3 print ("Shutting Down...") sleep(1) os.shutdown()So, the error I get is:
bios:337: [string 'menu2'] :32: 'end' expected (to close if at line 17)
Hope you can help...
What do you mean by tabbed twice ?
For me it looks like you want to select the options by pressing a key like TAB.
Greets loki
#8
Posted 29 March 2013 - 07:20 AM
Here. I fixed that error, as well as a few other errors I didn't want to just leave in your code (commented with what I changed).
function newMenu() --(Your comment: tabbed once) term.clear() term.setCursorPos(1,1) print ("Select One") --(Your comment: this is where the selections start) function selection() term.setCursorPos(10,10) print 'Login\n Shutdown' -- Changed to a regular string so the spacing works right (\n in a string like that means new line) input = read() -- input was not defined for the next line, so I set it to read() if input == "Login" then --(Your comment: Tabbed twice) term.clear() term.setCursorPos(1,1) pass1 = "Colton" -- I put these into quotes so that they are literal strings. Otherwise they refer to the variable with that name. pass2 = "Bacon" print ("Username:") input = read("*") if input == pass1 then -- I changed io.read() to input, so its the text that was just read, instead of reading new text. (I assume that is what was intended). Also removed 'to' after == term.clear() term.setCursorPos(1,1) print ("Password:") if io.read() == pass2 then term.clear() term.setCursorPos(1,1) end -- I added these two ends to close the if statements about pass1 and pass2 (cause of the end expected error) end elseif input == "Shutdown" then --(Your comment: from here it is tabbed 3) I removed the end for the 'if input == "Login" then', and changed this to elseif, so it only checks if the input is not Login. I also changed io.read() to input, so it uses the same input as when it checks for login. print ("Shutting Down...") sleep(1) os.shutdown() end end -- I added an end to close the function selection. end
#9
Posted 30 March 2013 - 04:34 AM
Thanks!
Edit: Hmm, When I try to run the program it doesn't even run...
Edit: Hmm, When I try to run the program it doesn't even run...
#10
Posted 30 March 2013 - 08:04 AM
You need to call the function selection after defining it, or it won't do anything.
#11
Posted 30 March 2013 - 10:17 AM
OK, Im kinda a noob, so how would I do that
#12
Posted 30 March 2013 - 10:23 AM
Call it the same way you would call print, sleep, or read, just
You'll also have to call newMenu the same way when you want it to run.
selection() -- If it took arguments, they would go between the parentheses
You'll also have to call newMenu the same way when you want it to run.
#13
Posted 30 March 2013 - 11:44 AM
Im sorry, But How would I do that... I have -
function newMenu() --Line 1 --Line 6 function selection()but it wont run for some reason
#14
Posted 30 March 2013 - 12:13 PM
After defining the functions using the function keyword, you call them separately from the code. Example:
function exampleFunction() --do stuff end exampleFunction() -- calls the function
#15
Posted 30 March 2013 - 12:20 PM
function selection() term.setCursorPos(10,10) print 'Login\n Shutdown' input = read() if input == "Login" then term.clear() term.setCursorPos(1,1) pass1 = "Colton" pass2 = "Bacon" print ("Username:") input = read("*") if input == pass1 then term.clear() term.setCursorPos(1,1) print ("Password:") if io.read() == pass2 then term.clear() term.setCursorPos(1,1) end end elseif input == "Shutdown" then print ("Shutting Down...") sleep(1) os.shutdown() end end function newMenu() term.clear() term.setCursorPos(1,1) print ("Select One") selection() end newMenu()That is all.
EDIT: Neatened.
#16
Posted 30 March 2013 - 12:22 PM
It still doesnt do anything :/ I removed them and then I got 28: <eof> expected. When I go there, it has a end.
EDIT: Ninja'd I will try that.
EDIT: Ninja'd I will try that.
#17
Posted 30 March 2013 - 12:29 PM
Thank you guys. I have made another menu thanks to your help. I can now base some of my other menus off of it.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users