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

[Lua Question] Creating a log-in with a subsequent program menu.

Started by Menschenfeind, 17 November 2012 - 11:28 AM
Menschenfeind #1
Posted 17 November 2012 - 12:28 PM
I'm a pretty major noob when it comes to this stuff, so please assume I don't have a clue what you're talking about.

I am attempting to create a program in startup so that I have to log in with a name and password, and after I do I will have access to a menu that will look something like this:

[Door]
Secret Door
Bridge
Stairs

Log Off

Where the brackets show you which option you've selected. Once you press enter I want it to take you to another smaller menu which will will essentially be:

[Enable]
Disable

Back

I have the log-in system down, my issue is with creating a menu that I can scroll through the options.

Here is what I use to log in with, I found this on the forums and modified it, but I can't recall from where or else I'd credit it.
Spoiler

os.pullEvent = os.pullEventRaw
term.clear()
term.setCursorPos(1,1)
password = "password"
write("Identification Required: ")
user = read()
if user == "User" then
		write("Authorization Code: ")
		input = read("*")
		if input == password1 then
term.clear()
term.setCursorPos(1,1)
				print("Welcome, User.")
sleep(1)
print("Logging in")
sleep(1)
term.clear()
term.setCursorPos(1,1)
print("Welcome, Mensch.")
print("Logging in.")
sleep(1)
term.clear()
term.setCursorPos(1,1)
print("Welcome, User.")
print("Logging in..")
sleep(1)
term.clear()
term.setCursorPos(1,1)
print("Welcome, User.")
print("Logging in...")
sleep(1)
term.clear()
term.setCursorPos(1,1)
print("Welcome, User.")
print("Login Successful!")
sleep(1)
term.clear()
term.setCursorPos(1,1)
sleep(1)
		else
				print("Authorization Invalid.")
				sleep(2)
				os.shutdown()
		end

else
		print("Clearance Invalid.")
		sleep(3)
		os.shutdown()
end


I was wondering if I would be able to use this menu code (also found here), to make it so I can scroll through the 4 options above, then let me choose "enable/disable", each of which will run a separate program which would essentially turn a redstone signal on or off.
Spoiler


function CUI(m)
n=1
l=#m
while true do
term.clear()
term.setCursorPos(1,2)
for i=1, l, 1 do
if i==n then print(i, " ["..m[i].."]") else print(i, " ", m[i]) end
end
print("Select a number[arrow up/arrow down]")
a, b= os.pullEventRaw()
if a == "key" then
if b==200 and n>1 then n=n-1 end
if b==208 and n<=l then n=n+1 end
if b==28 then break end
end
end
term.clear() term.setCursorPos(1,1)
return n
end


My issue isn't with creating programs for the enable/disable bits, more with how I would integrate the scrolling menu with my current log-in system and make the options link to executable programs.
Can anyone give me a shove in the right direction?
anonimo182 #2
Posted 17 November 2012 - 12:40 PM
instead of
 if b==28 then break end
use
 if b==28 and n==1 then yourFunction()
elseif b==28 and n==2 then
yourOtherFunction()
and so on...