Jump to content




Help with os.pullEvent()


  • You cannot reply to this topic
5 replies to this topic

#1 axel.codeFail()

  • Members
  • 47 posts
  • LocationA bit lost

Posted 18 April 2014 - 02: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.

#2 Grim Reaper

  • Members
  • 503 posts
  • LocationSeattle, WA

Posted 18 April 2014 - 03: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".

#3 axel.codeFail()

  • Members
  • 47 posts
  • LocationA bit lost

Posted 18 April 2014 - 03:06 AM

View PostGrim Reaper, on 18 April 2014 - 03:01 AM, said:

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.

#4 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 18 April 2014 - 03: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)

#5 axel.codeFail()

  • Members
  • 47 posts
  • LocationA bit lost

Posted 18 April 2014 - 03:31 AM

View PostKingofGamesYami, on 18 April 2014 - 03:08 AM, said:

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.

#6 Grim Reaper

  • Members
  • 503 posts
  • LocationSeattle, WA

Posted 18 April 2014 - 03:42 AM

View PostKingofGamesYami, on 18 April 2014 - 03:08 AM, said:

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users