26 posts
Location
Southern Oregon
Posted 18 November 2013 - 02:32 AM
I am writing a program compatible with turtles through use of their built in terminal a player can set them to common tasks like building or digging etc. I am getting ready to implement a feature where as the player may set all the parameters allowed for an order in my program normally only rather than issuing the order (or block of code) I instead write that code to a new program file called startup on the disk for obvious reasons. I am having trouble understanding how i can go about storing the block of code in a new file i create. must this be done as a string written to the file? and so i must have a large tostring() called containing all the code and parameters? or is this just an insane premise to have a program write another program with special conditions so that the disk may then start turtles about the task defined by the first program?
7083 posts
Location
Tasmania (AU)
Posted 18 November 2013 - 05:16 AM
So if I've got this right, you want to write a program that writes a disk which another turtle can boot off?
Well, if you specifically wanted to do it that way, then yeah: You'd open a file handle to write to, then write one or more strings to it until all the commands are in there.
However, while novel, having your program write more programs probably isn't the best way to pull this off. It'd likely be easier to write two scripts manually: One which writes a "summary" of the user's commands to a file on the disk (
textutils.serialize() being a really easy way to do that), and copies the second script there too. The second script would be the actual "startup" script the turtles boot from, which reads the "summary" file and performs the tasks it describes.
26 posts
Location
Southern Oregon
Posted 20 November 2013 - 01:30 AM
yeah that makes a lot of sense. so in essence I'm just storing the principal variables in the summary file that will be read so the boot can behave in the proper manner. thanks that will help a ton