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

closing a program when finished

Started by DusterTheFirst, 23 June 2016 - 10:31 AM
DusterTheFirst #1
Posted 23 June 2016 - 12:31 PM
i have a program that periodicly opens this:
local todofile = fs.open("disk/todo.txt", "r")
local todo = peripheral.wrap("monitor_9")
todo.setCursorPos(1,2)
local towrite = todofile.readAll()
todofile.close()
todo.write(towrite)

in multishell and i cant get it to close its tab once it is done. there ends up being many of them just saying press any key to end/close

how would i do this?
Emma #2
Posted 23 June 2016 - 06:34 PM
Not tested, but if it's asking for a key you can give it a fake key press like so:

os.queueEvent("key",42)
That way, the next time os.pullEvent is called it will return a key event for key 42
DusterTheFirst #3
Posted 24 June 2016 - 01:59 PM
Not tested, but if it's asking for a key you can give it a fake key press like so:

os.queueEvent("key",42)
That way, the next time os.pullEvent is called it will return a key event for key 42
i just want the program to terminate itself
CrazedProgrammer #4
Posted 24 June 2016 - 02:04 PM
return
Edited on 24 June 2016 - 12:05 PM
DvgCraft #5
Posted 24 June 2016 - 02:33 PM
Add this code to the end of your program:

os.queueEvent( "myProgramIsFinished" ) --Rename this
sleep( 0 )
multishell.setFocus( multishell.getCurrent() )

And create another program that will execute the other program:

shell.openTab( "path/to/file" )
os.pullEvent( "myProgramIsFinished" ) --Rename this
local currentTab = multishell.getFocus()
sleep( 0 )
multishell.setFocus( currentTab )
DusterTheFirst #6
Posted 26 June 2016 - 02:22 AM
thanks
Edited on 26 June 2016 - 12:25 AM