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

Console Timeout. Buggy?

Started by TrinaryAtom, 15 December 2012 - 01:34 AM
TrinaryAtom #1
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.
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.
theoriginalbit #2
Posted 15 December 2012 - 03:20 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.
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.

Change the following line of code


if argo == loginTime then

to something like this


if evt == "timer" and argo == loginTime then

and tell us how that goes :)/>
TrinaryAtom #3
Posted 15 December 2012 - 01:35 PM
Change the following line of code


if argo == loginTime then

to something like this


if evt == "timer" and argo == loginTime then

and tell us how that goes :)/>/>
Alright, cool I'll see how it goes. Although I don't see how adding an another layer of detection will fix the problem. If I don't post a reply then it is assumed that it worked. (Will try to post in a week if I don't forget)
theoriginalbit #4
Posted 15 December 2012 - 02:42 PM
Change the following line of code


if argo == loginTime then

to something like this


if evt == "timer" and argo == loginTime then

and tell us how that goes :)/>/>
Alright, cool I'll see how it goes. Although I don't see how adding an another layer of detection will fix the problem. If I don't post a reply then it is assumed that it worked. (Will try to post in a week if I don't forget)

yeh sorry its the only thing i could think of that could have been causing issue. unless i missed it somewhere else