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

Can't seem to leave a loop....

Started by xxslasherrmx, 25 December 2014 - 04:13 AM
xxslasherrmx #1
Posted 25 December 2014 - 05:13 AM
So while trying to make a mini-os for my news station, I have come across a slight issue. When logging in, even if you get the correct password it still claims incorrect. It doesn't seem like I made any errors…. Any thoughts? Here's the snippit part with the login

term.clear()
term.setCursorPos(1,1)
cPrint("Hello, welcome to NYT head computer.")
	  while true do
cPrint("Enter editor name")
EN = read()
if fs.exists("Editors/" ..EN) == true then
file = fs.open("Editors/" ..EN, "r")
local fileData = {}
local line = file.readLine()
repeat
table.insert(fileData,line)
line = file.readLine()
until line == nil
file.close()
local PassFile = fileData[1]
		break
else
	   cPrint("No Editor Found... Create One?")
			  sleep(1)
			  yyN()
				end
				end
				local PW = false
		   repeat  
	   cPrint("Please insert Password")
local pss = read()
	  if pss == PassFile or PW then
			cPrint("Welcome!")
					break
	   else
			 cPrint("Wrong Pass..")
						 end
				 until pss == PassFile

my full code is here http://pastebin.com/MZZfrW14
Dog #2
Posted 25 December 2014 - 06:12 AM
Your 'if/then' syntax is a little off.

Instead of…

if pss == PassFile or PW then

try…

if pss == PassFile or pss == PW then
Edited on 25 December 2014 - 05:13 AM
Cycomantis #3
Posted 25 December 2014 - 06:18 AM
This line

local PassFile = fileData[1]


is local to this if statement

if fs.exists("Editors/" ..EN) == true then


which means that what was returned is not available in the repeat loop and thus PassFile is nil. Declare it as local outside of the if block to make it local to the function or program so that it is available through out the code.


term.clear()
term.setCursorPos(1,1)
local PassFile --add this
cPrint("Hello, welcome to NYT head computer.")
		  while true do
cPrint("Enter editor name")
EN = read()
if fs.exists("Editors/" ..EN) == true then
file = fs.open("Editors/" ..EN, "r")
local fileData = {}
local line = file.readLine()
repeat
table.insert(fileData,line)
line = file.readLine()
until line == nil
file.close()
PassFile = fileData[1] --remove local
				break
else
		   cPrint("No Editor Found... Create One?")
						  sleep(1)
						  yyN()
								end
								end
								local PW = false
				   repeat  
		   cPrint("Please insert Password")
local pss = read()
		  if pss == PassFile or pss == PW then --syntax correction as pointed as previously
						cPrint("Welcome!")
										break
		   else
						 cPrint("Wrong Pass..")
												 end
								 until pss == PassFile
Edited on 25 December 2014 - 05:20 AM
SpencerBeige #4
Posted 30 December 2014 - 12:23 AM
if you cant leave a loop, use break command
Cycomantis #5
Posted 30 December 2014 - 04:24 AM
if you cant leave a loop, use break command

You didn't look very close did you? He has the break, just having a hard time meeting the condition to trigger it.