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

Continuously run program

Started by Matthewaj, 29 April 2012 - 12:47 AM
Matthewaj #1
Posted 29 April 2012 - 02:47 AM
Is there a way to make a program where you cannot exit and it continuously runs?
Luanub #2
Posted 29 April 2012 - 02:57 AM
You can use an infinite while loop


while true do
insert code here
end

The only way to stop that will be with either ctrl+t, ctrl+r, or ctrl+s.

Well or if you tell it to break the loop by doing something like


while true do
some stuff
if input == "exit" then -- can be whatever you want just an example
  break -- will stop the while loop
end
end
Lyqyd #3
Posted 02 May 2012 - 03:44 AM
If you then also pull raw events instead of sleeping or using read(), you can block the terminate key sequence. Just run that program from the startup and it'll be a bit more difficult to bypass.
ComputerCraftFan11 #4
Posted 02 May 2012 - 03:50 AM
You can use an infinite while loop


while true do
insert code here
end

The only way to stop that will be with either ctrl+t, ctrl+r, or ctrl+s.

Well or if you tell it to break the loop by doing something like


while true do
some stuff
if input == "exit" then -- can be whatever you want just an example
  break -- will stop the while loop
end
end

Like above, you can add os.pullEvent = os.pullEventRaw to your program. Like this:

os.pullEvent = os.pullEvenRaw

while true do
insert code here
end

The only way to stop that will be with either ctrl+t, ctrl+r, or ctrl+s.

Well or if you tell it to break the loop by doing something like


os.pullEvent = os.pullEvenRaw

while true do
some stuff
if input == "exit" then -- can be whatever you want just an example
  break -- will stop the while loop
end
end
Luanub #5
Posted 02 May 2012 - 03:58 AM
You can use an infinite while loop


while true do
insert code here
end

The only way to stop that will be with either ctrl+t, ctrl+r, or ctrl+s.

Well or if you tell it to break the loop by doing something like


while true do
some stuff
if input == "exit" then -- can be whatever you want just an example
  break -- will stop the while loop
end
end

Like above, you can add os.pullEvent = os.pullEventRaw to your program. Like this:

os.pullEvent = os.pullEvenRaw

while true do
insert code here
end

The only way to stop that will be with either ctrl+t, ctrl+r, or ctrl+s.

Well or if you tell it to break the loop by doing something like


os.pullEvent = os.pullEvenRaw

while true do
some stuff
if input == "exit" then -- can be whatever you want just an example
  break -- will stop the while loop
end
end

Just remember that by doing something like "os.pullEvent = os.pullEventRaw" you may be messing with the global os.pullEvent and this may overflow into other programs. If your going to go this route the best thing to do is to do some cleanup prior to exiting your script and restore the original os.pullEvent function(unless it doesnt matter and you do not want to use ctrl+t any where).
Graypup #6
Posted 03 July 2012 - 10:40 PM
local os.pullEvent = os.pullEventRaw?
MysticT #7
Posted 03 July 2012 - 11:53 PM
local os.pullEvent = os.pullEventRaw?
Have you tried that? It won't work, you can't make a variable (the pullEvent function) inside a table (the os api table) local.