Posted 15 December 2012 - 02:34 AM
Title of Post should be somthing like "os.startTimer()- Buggy?"
I have made this Input code and all works fine. Except when i allow the timer part to run in it. It works like 75% of the time but sometimes it likes to go off early or right when i press a button.
What I'm trying to achieve is when the computer is left alone on this section of code, it will terminate its self.
Also, If you like this bit of code you can feel free to use it for your self.
Its a custom input function designed for a username and password, only this time, you can tab back and forth until you hit enter either twice or once. Depending on which one you are currently on.
I have made this Input code and all works fine. Except when i allow the timer part to run in it. It works like 75% of the time but sometimes it likes to go off early or right when i press a button.
What I'm trying to achieve is when the computer is left alone on this section of code, it will terminate its self.
Spoiler
function loginBox()
local iInput = 1
local uInput = 0
local pInput = 0
local inUser = ""
local inPass = ""
local barLine = "+----------------------------+"
local inputLine1 = "| Username: ................ |"
local inputLine2 = "| Password: ................ |"
-- loginTime = os.startTimer(30)
while true do
cwrite(barLine,4)
clearLine(5)
cwrite(inputLine1,5)
ux = math.ceil((xx/2)-(string.len(inputLine1)/2)+12)
xwrite(inUser,ux,5)
if iInput == 1 then
write("_")
end
clearLine(6)
tempPass=inPass:gsub(".","*")
cwrite(inputLine2,6)
xwrite(tempPass,ux,6)
if iInput == 2 then
write("_")
end
cwrite(barLine,7)
local evt, argo, argt, argr = os.pullEvent()
-- if argo == loginTime then cwrite("Auto Shutdown in 5 seconds",9) sleep(5) os.shutdown() end
if evt == "char" then
if iInput == 1 then
if uInput <= 15 then
inUser = (inUser .. argo)
uInput = uInput + 1
end
elseif iInput == 2 then
if pInput <= 15 then
inPass = (inPass .. argo)
pInput = pInput + 1
end
end
end
if argo == 14 then
if iInput == 1 then
if uInput >= 1 then
inUser = string.sub(inUser,1,#inUser-1)
uInput = uInput - 1
end
elseif iInput == 2 then
if pInput >= 1 then
inPass = string.sub(inPass,1,#inPass-1)
pInput = pInput - 1
end
end
end
if argo == 15 then
-- loginTime = os.startTimer(30)
if iInput == 1 then
iInput = 2
elseif iInput == 2 then
iInput = 1
end
end
if argo == 28 then
if iInput == 1 then
-- loginTime = os.startTimer(30)
iInput = 2
else
return inUser,inPass
end
end
end
end
Also, If you like this bit of code you can feel free to use it for your self.
Its a custom input function designed for a username and password, only this time, you can tab back and forth until you hit enter either twice or once. Depending on which one you are currently on.