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

[Question] A couple of questions regarding turtles and programs from disks

Started by rugrast, 01 July 2012 - 10:57 PM
rugrast #1
Posted 02 July 2012 - 12:57 AM
I'm writing a program for my turtle that will allow it to deliver some TNT x blocks away, activate it, and detonate it. All of these lines are within disk/bomb.

I have two questions:

1. When I type "turtle.forward(x)" (with "x" being the number of desired blocks), he only goes forward one block. I can only make him go forward more than one block by typing "turtle.forward()" as many times as blocks I want him to move. Is that the only way to get him to move multiple blocks, or am I doing it wrong?

2. I can get the turtle to move to the spot I want it to, and I can get it to place a block. But I cannot get it to "redpulse." This works when using just the Turtle OS, but not when using disk/bomb. Can I not use built-in programs from the turtle inside my own programs in the disk?

(Also, just a question of terminology: what would I call "disk/bomb"? Is that a function? Or is it a program?)
MysticT #2
Posted 02 July 2012 - 01:42 AM
1) turtle.forward doesn't accept arguments, it just moves the turtle 1 block. So you need to use a loop to repeat the function call:

local function forward(x)
  for i = 1, x do
    turtle.forward()
  end
end

forward(10) -- move forward 10 blocks

2) redpulse is a program, to use programs inside a program, you can use shell.run:

shell.run("Program Name", "arguments")
But I don't recommend using it for things that can be done with simple function calls:

rs.setOutput("<side>", true)
sleep(0.2)
rs.setOutput("<side>", false)

Files that you can run are programs, functions are blocks of code you can use inside a program.
rugrast #3
Posted 02 July 2012 - 04:10 AM
Very cool. So calling "redpulse" is the same type of file as "disk/bomb" or "startup" (for locking doors)?

Now then, for that first block of code you provided (and this is auxillary to what I actually need to know), I'm creating a function, yes? And the function is to create a loop of the turtle.forward()…command? How does the i = 1, x do come into play?

Also, thanks. I played with this turtle for the longest time before surrendering to outside help. But, now that I've done it, I'm bound to ask all sorts of irrelevant questions. Feel free to cut me off. :P/>/>
MysticT #4
Posted 02 July 2012 - 04:27 PM
The loop inside the function is a for loop:

for i = start, end[, increment] do
end
You can read more about for and other loops and stuff in the lua manual.