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

[LUA] Reusing a set of instructions

Started by Heisenbugs, 07 January 2013 - 05:07 PM
Heisenbugs #1
Posted 07 January 2013 - 06:07 PM
Hi there. I'm fairly new to computercraft/lua/programming, but learning fast. One thing I'm wondering about is, is there a way to write out a set of instructions (eg for a mining turtle) and somehow save them and reuse them throughout a lua program without needing to retype everything? This is in a case where looping is not applicable. Thank for the help.
Lyqyd #2
Posted 07 January 2013 - 06:22 PM
Are you looking for functions?


function doStuff()
  turtle.up()
  turtle.forward()
  turtle.down()
  turtle.back()
end

doStuff()
--later
doStuff()
Vogon_Jeltz #3
Posted 08 January 2013 - 05:30 AM
By 'set of instructions' I assume you mean programs?

You can save your programs to disks, so you can reuse them when you break your turtle, or on another turtle. You'll need a disk drive and a floppy disk. There's a forum thread here on saving programs to a floppy disk.