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

need help with print

Started by michielewiel, 18 March 2012 - 11:14 AM
michielewiel #1
Posted 18 March 2012 - 12:14 PM
hey, first of all i woud like to say that the mod is awsome
But i got a little problem i am just starting to learn lua and when i made my first little programm i came across a problem
it runned the programm like it is supposed to but i completly ignored my "print"
anyway here is the code:


local master = "michiel"
local password= "virus"
local x= "welcome to the system master"
term.clear()
print("who are you")
sleep(2)
local user = io.read()
if user ~= master then
print("u have no premision")
os.shutdown()
end
if user == master then
print("welcome")
sleep(2)
end
print("what is the password?")
local userpass = io.read()
if userpass ~= password then
print("good try but get of this computer")
os.shutdown()
if userpass == password then
print(x)
sleep(2)
end
end

it ignore's print("good try but get of this computer") and print(x)
ps: i know it is kinda messy but it is my first try with lua :D/>/>
with best regards michiel
natedogith1 #2
Posted 18 March 2012 - 12:18 PM
it will only check if userpass==password if uaserpass!=password
Liraal #3
Posted 18 March 2012 - 12:24 PM
What means you need:
if userpass ~= password then
print("good try but get of this computer")
os.shutdown()
end
if userpass == password then
print(x)
sleep(2)
end
michielewiel #4
Posted 18 March 2012 - 12:31 PM
thanks alot mate u realy hellped me out there anyway sorry for this stupid post
;p
Luanub #5
Posted 18 March 2012 - 10:44 PM
Or you could clean it up a little and just do an if else statement vs two if's.


if userpass == password then
print(x)
sleep(2)
else
print("good try but get off this computer")
os.shutdown()
end