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

[Lua][Error] Can't find the problem with my code.

Started by HavingPhun, 27 April 2012 - 07:20 PM
HavingPhun #1
Posted 27 April 2012 - 09:20 PM
So im making a program that will make it easier to control networks and redstone and eventually other things. I put it in two files for now so I could work on different parts of it. But I get odd errors.

RedControl.lua:

term.clear() term.setCursorPos(1,1)
term.write("Welcome to RedControl, \n Please enter your password.")
sleep(1)
term.setCursorPos(1,0)
input = read()

if input = ("password") then
term.clear()
term.setCursorPos(1,1)
term.write("Checking Password...")
sleep(5)
term.clear
term.setCursorPos(1,1)
term.write("Password Correct!")

else

term.clear()
term.setCursorPos(1,1)
term.write("Checking Password...")
sleep(5)
term.clear
term.setCursorPos(1,1)
term.write("Password Incorrect! Exiting program in 5 seconds...")
sleep(5)
exit()
end

term.clear
term.setCursorPos(1,1)
term.write("What would you like to do?")

I stopped here because of this error:

bios:206:  [string "RedControl.lua"] :7: 'then' expected
I have 'then' were it says the error is. Then I get an error in RedNetwork.lua:


--Output = ("")
--Input = ("")
Message = ("")
LastId = 0
Port = ("")
function configure()
term.write("What would you like your default port to be?")
Port = read()
end
function start()
term.clear
term.setCursorPos(1,1)
--term.write("What port is your modem on?")
--Port = read()
rednet.open(Port)
term.write("Starting Modem... /n")
sleep(3)
term.write("Modem Started. /n")
end
function talk(message)
term.write("What would you like to send? /n")
message = read()
Message = read()
rednet.broadcast(message)
term.write("Sending... /n")
Message = Message
end
function listen(duration, message)
term.write("How long would you like to look for a signal? Leave blank to search until one is found. /n")
duration = read()
id,Message = rednet.receive(duration)
term.write("A message has been received from computer number" .. id .. "It is:" message "/n")
end
function reply(message)
term.write("Replying to most recent computer communicated with... /n")
term.write("What would you like to say?")
message = read()
rednet.send(LastId, message)
end

This is the error I get:


bios:206: [string "RedNetwork.lua"] :14: '=' expected

Which again there is an '=' sign. Can someone help me with this. Also I am gonna change these a little as they are. Is there any other problems that you guys see or things you think I should change? Thanks.
Luanub #2
Posted 27 April 2012 - 09:32 PM
The main thing I see in the first script is exit() unless you have that as a function somewhere in your script its not a valid function. Try replacing it with error(). There are also several term.clear's in both scripts that are missing ()'s at the end of them.

Other then that term.write can just simply be write, and you dont need the ()'s in the if statement(it should work with them though).

Also on the second where your declaring empty strings try just doing Port = ""
HavingPhun #3
Posted 27 April 2012 - 09:37 PM
Ok thanks ill see if i can fix it.
OmegaVest #4
Posted 27 April 2012 - 09:39 PM
Okay, in RedControl, the 'then' is there, but you also are missing an '='. You have a call, not a comparison. Should be

if input == "password" then

I have no idea what's with the other script. Which, btw, did you purposefully comment out that line? If it still throws the error if you did means it's a bug. Delete the line, save the program, exit the program, then reopen it and retype it. That usually works for me.
HavingPhun #5
Posted 27 April 2012 - 11:07 PM
I did purposefully comment out those lines, I didn't know if i was gonna keep them or not so I commented them. There gone now. I rewrote RedControl.lua and changed the comparisons to be '==' instead of '='. That fixed the error but now theres a new one. RedControl:
 
Luke = "mypassword" 
Guest = "password" 
Password = "" 
Status = "Logged Out" 
Account = "" 
function Login(account, password) 
if Status == "Logged In" then 
term.write "Already logged in! Please log out to log in to another account. /n" 

else

 if password == account then 
term.write "Password correct! Welcome User. /n" 
Status = "Logged In /n"

else

term.write "Incorrect password! Closing program in 5 seconds! /n" 
error() 
end 
end 
end 

function Logout(response, account2, password2) 
if Status == "Logged Out" then 
term.write "You are already logged out. Would you like to Log In? /n" 
response = read() 
response = response 
if response == "Yes" then 
Login(account, password) 
term.write "Type account name: /n" 
account = read() 
account = account 
term.write "Type account password: /n" 
password = read() 
password = password 
Login(account2 , password2) 

else
term.write "Ok, type 'Login()' later if you would like to login. /n" 
end 

else
term.write "Logging out in 5 seconds... /n" 
sleep(5) 
Status = "Logged Out"
term.write "Logged Out. /n" 
end end end 

The new error is:
 
error for redcontrol: bios:206: [string "RedControl.lua"] :55: '<EOF>' expected 

I have no idea what eof is. Line 55 is the last 'end' in the program. Is there one too many ends? Isn't eof for file i/o? Can someone help me here? Also thanks to OmegaVest and luanub for the help so far.
MysticT #6
Posted 28 April 2012 - 12:17 AM
You have an extra end at the end (XD), remove it an it should work (I didn't read the whole code, just searched for extra ends, wich cause that error).
Try indenting the code, it makes it more readable so this things don't happen.
HavingPhun #7
Posted 28 April 2012 - 10:46 PM
You have an extra end at the end (XD), remove it an it should work (I didn't read the whole code, just searched for extra ends, wich cause that error). Try indenting the code, it makes it more readable so this things don't happen.
Ok thanks. Thats what I thought it was. Didn't test it because I had to leave just as i typed this. I had it a little neater before but i had to edit my post and it messed up the spacing in my post.