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

[Error] For Project

Started by Popeye, 17 April 2013 - 07:14 AM
Popeye #1
Posted 17 April 2013 - 09:14 AM
Hello Everyone,

I'm working on a little Bank. And I have gotten an Error.

Error:


Code:


-- [Bank] --

term.setTextColor(colors.cyan)

askingForInput = print("Welcome to the Bank! What Would you like to do? Login or Register: ")

if askingForInput == 'Register' then
   local input = read()
   registering = print("Enter the Username you want to Register with: ")
end

if askingForInput == 'Login' then
   local input = read()
   loggingIn = print("Enter your Username: ")
end

if loggingIn == registering then
   local input = read()
   print("Logged in as "..registering)
end

Anyone have a Solution?
Engineer #2
Posted 17 April 2013 - 10:29 AM
It is erroring because registering = pint("that text")
You can do just plain print("the text"), without an variable, here let me show you some code:

--[bank]--
print("Welcome to the Bank! What Would you like to do? Login or Register")
local answer = string.lower(read()) -- String.lower makes it always lower case. Even if you type REGISTERING OR LOGIN

local username -- make local visible out of the if statement
if answer == "login" then
	print("What is your username?")
	username = read()
elseif answer == "registering" then
	print("Enter your username:") -- Does the same as the previous, but just for the sake of showing
	username = read()             -- ^
end

print("Welcome "..username)

So you do the read() after you have printed it, otherwise it would make no sense..
And as you can see, the print("text") is never hold by a variable in my code.

Please, if you have questions about the code, or something else under the same topic, please ask :)/>
Popeye #3
Posted 18 April 2013 - 05:29 AM
Another Error:
bios:337: [string "Bank"]:17: '<eof>' expected

Code:


-- [Bank] --

term.setTextColor(colors.cyan)

takingOrder = print("Welcome to the Bank! What Would you like to do? Login or Register")

local takingOrder = string.lower(read())
local usernameName

if takingOrder == "login" then
	logingIn = print("What is your Username?: ")
	usernameName = read()
end
if logingIn == registerName then
	print("You have Logged in as  "..usernameName)
end
elseif takingOrder == "register" then
   registerName = print("Enter your Username: ")
   usernameName = read()		  
end
SadKingBilly #4
Posted 18 April 2013 - 05:46 AM
Several things. First, get rid of line nine completely. Not only is it useless, I'm pretty sure it's also against Lua syntax and is breaking the code. Secondly, the syntax for an if-elseif is not "if then body end elseif then body end", it's "if then body elseif then body end". Get rid of the end on line seventeen. Finally, what is going on with lines six, ten, and nineteen? I don't actually understand what you're trying to do there, but you can't store a print function in a variable. It will just execute the print function upon definition and the variable will be nil. Also, you're comparing the values of variables that don't even exist. Like in line fifteen: not only is logingIn nil, registerName hasn't been defined at all.
Zudo #5
Posted 18 April 2013 - 05:58 AM
Another Error:
bios:337: [string "Bank"]:17: '<eof>' expected

Code:


-- [Bank] --

term.setTextColor(colors.cyan)

takingOrder = print("Welcome to the Bank! What Would you like to do? Login or Register")

local takingOrder = string.lower(read())
local usernameName

if takingOrder == "login" then
	logingIn = print("What is your Username?: ")
	usernameName = read()
end
if logingIn == registerName then
	print("You have Logged in as  "..usernameName)
[b]end --remove this end[/b]
elseif takingOrder == "register" then
   registerName = print("Enter your Username: ")
   usernameName = read()		  
end
Popeye #6
Posted 18 April 2013 - 06:05 AM
Another Error:
bios:337: [string "Bank"]:17: '<eof>' expected

Code:


-- [Bank] --

term.setTextColor(colors.cyan)

takingOrder = print("Welcome to the Bank! What Would you like to do? Login or Register")

local takingOrder = string.lower(read())
local usernameName

if takingOrder == "login" then
	logingIn = print("What is your Username?: ")
	usernameName = read()
end
if logingIn == registerName then
	print("You have Logged in as  "..usernameName)
end --remove this end
elseif takingOrder == "register" then
   registerName = print("Enter your Username: ")
   usernameName = read()		  
end

Why did'nt Post any Text with Your Reply?
Neekow #7
Posted 18 April 2013 - 06:10 AM
he did, look comments on your code ;)/>
Popeye #8
Posted 18 April 2013 - 06:23 AM
Ah! I see… Thanks.