Computercraft: Terminating a program

  • Please make sure you are posting in the correct place. Server ads go here and modpack bugs go here

thestig_992

New Member
Jul 29, 2019
9
0
0
So I've been writing a program with computercraft using pullEvents to monitor my factory, and as always I've run into a few bugs. However, the hotkeys to terminate a program dont seem to be working. crtl+t, crtl+s and ctrl+r all do nothing. Does anyone know if the keys have changed in FTB (mindcrack) or another way to stop a program without having to break the computer each time?
 

slay_mithos

New Member
Jul 29, 2019
1,288
0
0
Ctrl+R has to be maintained several seconds too, it will reboot the computer/turtle.

I also had hard time figuring this out, as it is not quite explained the right way, I guess.
 

Icarus White

New Member
Jul 29, 2019
234
0
0
I think the wiki alludes to this vaguely - it says while talking about the computers that you have to hold it down for several seconds - but it could be a little more clear about it, I think
 

IBurn36360

Member
Jul 29, 2019
57
0
16
If you have used and calls to the raw input event (os.pullEvent = os.pullEventRaw), you will be unable to terminate the program as key events are now casted to an event themselves. The only way to reverse this would be to remove that line, or create the terminate event as a separate thread of your script.

EDIT: You could also revoke that condition by adding The following:
Code:
local pullEvent = os.pullEvent
os.pullEvent = os.pullEventRaw
 
 
-- This can be added later on to revoke the change
os.pullEvent = pullEvent
 

slay_mithos

New Member
Jul 29, 2019
1,288
0
0
You could also intercept the raw event before sending it to pullEvent, that would let you make conditionnals for this kind of stuff.
No idea on what are the raws for such event though.
 

thestig_992

New Member
Jul 29, 2019
9
0
0
Thanks for the help everyone, I just needed to hold down crtl+t - must have missed that in the wiki :)

Now if only I could get my deployer to work with my rainmaker :S
 

CoderJ

New Member
Jul 29, 2019
135
0
0
using parallel.waitForAny() and making a quit function for your program is always a good idea ;) Here's a very rough example, there are some quirks to it but it should work 99% of the time (unless the other functions somehow hang the program).

Code:
quit = false
 
function quitProgram()
  local event, param1 = os.pullEvent("char)
  if param1 == "q" then
    quit = true
  end
end
 
while true do
  parallel.waitForAny(quitProgram, otherStuff)
 
  if quit then
    print("Quitting....")
    break
  end
 
  --Other code
  sleep(0.05) --Sleep 1 tick
end
 
  • Like
Reactions: thestig_992