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

Background Loop; Computer Still Usable

Started by RPMGamer, 11 February 2018 - 05:37 PM
RPMGamer #1
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! :)/>
KingofGamesYami #2
Posted 11 February 2018 - 11:33 PM
Why not just catch the terminate event? And when it's terminated lock everything out.
RPMGamer #3
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?
KingofGamesYami #4
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.
RPMGamer #5
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?
RPMGamer #6
Posted 13 February 2018 - 10:24 PM
Nevermind, it works with a variablehere = read(). Thanks!