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

Pausing the execution of a program

Started by doublequestionmark, 06 March 2016 - 03:46 PM
doublequestionmark #1
Posted 06 March 2016 - 04:46 PM
So I have two programs, program a and program b. program a is ran first and then a starts b…

Program a

--load program b into a
f = fs.open("program b", 'r')
b = loadstring(f.readAll())
f.close()
setfenv(b, getfenv())
b()

program b

i = 1
while true do
	print(i)
	i = i + 1
end

Is there a way for program a to pause the execution of program b without tampering with program b's code
for example:

desired outcome

b: 1
b: 2
b: 3
b: 4
a: button pressed, pausing execution of program b
a: button pressed again, resuming program b
b: 5
b: 6
...
HPWebcamAble #2
Posted 06 March 2016 - 06:01 PM
In this specific example, no, not without the Lua debug API (which is disabled in CC)

But in a program that calls os.pullEvent (like it should ;)/> ), you can make a program that manages what events get passed to program b. See the parallel API for an example.