47 posts
Location
A bit lost
Posted 18 April 2014 - 03:01 AM
I'm trying to make a verifying step to a program, but for some reason it doesn't pickup the key press.
shell.run("clear")
if fs.exists("startup") then
print("Are you sure you want to replace your current startup file? Y/N")
while true do
ev, but = os.pullEvent()
if but == y then
break
elseif but == n then
print("Ok, I won't override it.")
sleep(.5)
print(textutils.slowWrite("rebooting..."))
sleep(1)
os.reboot()
end
end
fs.delete("startup")
fs.copy("VectOS/programs/startup", "startup")
else
fs.copy("VectOS/programs/startup", "startup")
end
os.reboot()
When I press "y" or "n", it does nothing.
504 posts
Location
Seattle, WA
Posted 18 April 2014 - 04:01 AM
When you write
but == y
, the interpreter thinks that you are trying to compare the value stored in 'but' with the value stored in the variable 'y'. Simply put, you forgot the quotes around y and n which tell the interpreter that they are literal strings.
To fix this, just do this:
if but == "y" then
elseif but == "n" then
. This way the interpreter will understand that you want to compare the value stored in 'but' to the literal string value of "y" or "n".
47 posts
Location
A bit lost
Posted 18 April 2014 - 04:06 AM
When you write
but == y
, the interpreter thinks that you are trying to compare the value stored in 'but' with the value stored in the variable 'y'. Simply put, you forgot the quotes around y and n which tell the interpreter that they are literal strings.
To fix this, just do this:
if but == "y" then
elseif but == "n" then
. This way the interpreter will understand that you want to compare the value stored in 'but' to the literal string value of "y" or "n".
Oh, thanks.
3057 posts
Location
United States of America
Posted 18 April 2014 - 04:08 AM
You may also want to change os.pullEvent() to os.pullEvent( "key" ) if you want only key events as input (eg. it won't pick up mouse clicks on advanced monitors)
47 posts
Location
A bit lost
Posted 18 April 2014 - 04:31 AM
You may also want to change os.pullEvent() to os.pullEvent( "key" ) if you want only key events as input (eg. it won't pick up mouse clicks on advanced monitors)
I'm have it set so that nothing will happen unless the variable 'but' is equal to "y" or "n", and no other event (to my knowledge) will send those.
504 posts
Location
Seattle, WA
Posted 18 April 2014 - 04:42 AM
You may also want to change os.pullEvent() to os.pullEvent( "key" ) if you want only key events as input (eg. it won't pick up mouse clicks on advanced monitors)
Actually, filtering for only key events would cause the program to never work properly; the variable 'but' would always contain a number rather than the character value returned by a character event.