r/ComputerCraft • • Dec 12 '16

Nested programs or functions?

I'm writing a utility program that will give me about 20 different functions that the computer can perform all red stone related.

Each function is relatively small, is it better to split them into seperate programs to be called on or have a small api of functions that the main program can use.

Also i need the program to persist after restarts etc so what is the best way to do this.

2 Upvotes

8 comments sorted by

View all comments

1

u/revereddesecration Dec 12 '16

have a small api of functions that the main program can use

This.

Also i need the program to persist after restarts etc so what is the best way to do this.

There are no good ways to do this. There are some bad ways that involve serialising the state of the program into a file but this can fail.

1

u/flauntin Dec 12 '16

What I was thinking is having the program write to startup.

Say we are using the nested programs Shell.run("function")

Or if I use the api Shell.run("api") While true do Api.function() End

That's if it is possible to write to startup from another program I haven't got that far yet

4

u/revereddesecration Dec 12 '16

Don't write to startup. Have a startup program that reads from a file that you write to.