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

[finished]forward-turtle

Started by Jappards, 13 April 2013 - 05:06 AM
Jappards #1
Posted 13 April 2013 - 07:06 AM
I created this script to learn arguments.
if you have it installed on a mining turtle, it will dig the block infront of it, if there is a block infront of it.

code:

local tArgs= {...}
local x= tonumber(tArgs[1])
function digFront()--optional, works only on the mining turtle.
if turtle.detect() then
  turtle.dig()
end
end
if x == nil then
digFront()--optional
turtle.forward()
else
for i= 1,tArgs[1] do
  digFront()--again optional
  turtle.forward()
  print(x-i)
end
end
Note: i don`t use fuel on my turtles.

common glitches
Spoilernothing

how to use:
  1. run the program, the argument
Lyqyd #2
Posted 13 April 2013 - 08:14 AM
Oh, for crying out loud. Use. The. Report. Button.

Moved to Ask a Pro.
Jappards #3
Posted 13 April 2013 - 08:18 AM
next time i will.
LazyBoot #4
Posted 13 April 2013 - 12:50 PM
Most likely you need to do
tonumber(tArgs[1])
danny_delmax1 #5
Posted 13 April 2013 - 02:08 PM
I created this script to learn arguments.

code:

local tArgs= {...}

for i= 1,tArgs[1] do
turtle.forward()
print(tArgs[1]-1)
end

Note: i don`t use fuel on my turtles and i am fixing that bug, but i can`t solve it.
how do i fix this bug?

common glitches
Spoilerthe program prints the same number every time

how to use:
  1. run the program with an argument of how many blocks the turtle needs to travel.
not working code(don`t use, crashes the (ingame) turtle)

local tArgs= {...}
local x= tArgs

if tArgs == nil then
turtle,forward()
else
for i= 1,tArgs[1] do
  turtle.forward()
  print(x[1]-1)
end
end

when i run this code it says:forward:6(the else part): syntax error.

Regarding the first code, your never reducing the amount in tArgs[1], your printing tArgs[1] - 1 repeatedly. Heres the revised first section:


local tArgs= {...}

for i = 1, tArgs[1] do
	turtle.forward()
	print(tArgs[1] - i) -- prints the lowered tArgs[1]
end


Heres the other code section, that i would rather use:



local tArgs= {...}
local x = tonumber(tArgs[1]) -- This turns x into the value of the first value in table tArgs- you were missing [1]
-- tonumber(tArgs[1]) turns it into a number or nil

if x == nil then -- again, missing [1] - but we are using the number form of tArgs[1] defined in x
	turtle.forward() -- turtle.forward(), not turtle,forward() - use period, not comma
else
	for i = 1, x do   -- again, using the number only form of tArgs[1] defined in x
	  turtle.forward()
	  print(x - i) -- [1] is only used in tables- x is a simple variable
	  -- (x - i) will make it print the amount of movements remaining
	  end
end

note: code is untested, but will hopefully be bug free. If you wanted X to be a table containing the same as tArgs, just say so and ill give an example code.

If you have any questions at all, don't hesitate to ask.
Jappards #6
Posted 13 April 2013 - 07:21 PM
thanks, i am going to update it in the first post, but that program was compleetly bug free.
Lyqyd #7
Posted 13 April 2013 - 08:53 PM
Moved by request.