Jump to content




Background Loop; Computer Still Usable

command lua computer

5 replies to this topic

#1 RPMGamer

  • Members
  • 6 posts

Posted 11 February 2018 - 06:37 PM

Hello, I have just began making a simple Operating System in ComputerCraft, with a sign in system. I want it to feel like you are free to do what you like with the OS and add some flexibility, but I also need restrictions to make it harder to cheat. I have made the username system terminatable with a variable of Mode, since I have an admin user and a guest, both with different passwords, but if you terminate it, it will have a value of 'nil'. I want to have an anti-cheat loop running in the background to detect whether your mode is set to nil, and if it is then it will end the loop but lock you out of everything on the computer until you restart. How do you make the loop run forever in the background, without stopping you from typing? If you do not understand what I mean, then leave a comment and I will try to explain more clearly. Thanks! :)

#2 KingofGamesYami

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

Posted 11 February 2018 - 11:33 PM

Why not just catch the terminate event? And when it's terminated lock everything out.

#3 RPMGamer

  • Members
  • 6 posts

Posted 12 February 2018 - 06:15 PM

What is the code to detect when it is terminated? Is there a way to read key presses or something so that it knows when you Ctrl+T?

#4 KingofGamesYami

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

Posted 13 February 2018 - 01:40 AM

Try the following:

while true do
  local event = {os.pullEventRaw()}
  if event[1] == "terminate" then
     print "the program will now end"
     break
  end
end
reference.


#5 RPMGamer

  • Members
  • 6 posts

Posted 13 February 2018 - 10:30 AM

It works, and it catches the terminate event, but I cannot type while it is in a loop (but I want it to be in a loop forever). Thanks for that code, as it will be useful for future programs, but is there a way to create a background loop that lets you type?

#6 RPMGamer

  • Members
  • 6 posts

Posted 13 February 2018 - 10:24 PM

Nevermind, it works with a variablehere = read(). Thanks!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users