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

Help

Started by Amokaci, 08 April 2013 - 05:58 AM
Amokaci #1
Posted 08 April 2013 - 07:58 AM
Hello i am a beginner in [LUA]

i hope the community can help me

i foun a very good script it is from Jaffa
(Jaffa's attack turtle program
– Version: 1.0.1.0)

and i wanna change it a little bit that i can use it for a Mining Turtle to make a auto cobblestonegenerator (with a filter in the back of the turtle and both are connected with 2x jacketwire)

all functions work only check () doesent work

i try to say the turtle every time u get in slot 1 64 cobble stone send a redstone signal to the Filter the the filter suck 64 cobble to the chest (barrel)
i have change many but still not work i hope u all can help me.

Code:
Spoiler– Jaffa's attack(digging) turtle program
– Version: 1.0.1.0

local hits = 0
local tries = 0
local movemode = false
local moveallowed = false
local tstop
local ignoredkeys = {["2"]=true, ["5"]=true, ["8"]=true}
local waittext = " - Wait"
local args = { … }
if args[1] == "movemodeon" then movemode = true end
if movemode == true then
local tx, ty = term.getCursorPos()
term.setCursorPos(1 ,ty - 1)
term.clearLine()
print("Jaffa's Attack programm")
end

function check()
if turtle.getItemCount(1) > 0 then for i =64, 1 do
turtle.select(i)
end
end
end
if turtle.select(1) then
rs.setOutput("top", true)
sleep(2)
rs.setOutput("top", false)
end

function keywait ()
while not tstop do
local event,key = os.pullEvent()
if (event == "key") and (key == 203) then
if not turtle.turnLeft() then print("Error turning left") end
elseif (event == "key") and (key == 205) then
if not turtle.turnRight() then print("Error turning right") end
elseif (event == "key") and (key == 200) and (moveallowed == true) then
if not turtle.forward() then print("Error moving forward") end
elseif (event == "key") and (key == 208) and (moveallowed == true) then
if not turtle.back() then print("Error moving back") end
elseif (event == "key") and (key == 76) and (movemode == true) then
if moveallowed == true then
moveallowed = false
print("Move lock enabled")
else
moveallowed = true
print("Move lock disbled")
end
elseif (event == "key") and (key == 72) and (moveallowed == true) then
if not turtle.up() then print("Error moving up") end
elseif (event == "key") and (key == 80) and (moveallowed == true) then
if not turtle.down() then print("Error moving down") end
– elseif (event == "char") and (not ignoredkeys[key]) then
– tstop = true
elseif (event == "char") and (key == "s") then
tstop = true
write(waittext)
end
end
end

function dig ()
while not tstop do
if turtle.digDown() then
hits = hits +1
else
sleep(0.1)
end
tries = tries + 1
end
end
function stats ()
local tx,ty = term.getCursorPos()
while not tstop do
sleep(2)
local percentage = (hits/tries) * 100
term.setCursorPos(1,ty)
term.clearLine()
term.setCursorPos(1,ty)
write("Hits: ")
write(hits)
write("/")
write(tries)
write(" (")
write(percentage)
write("%)")
end
write(waittext)
end

turtle.select(1)
print("Press S to stop the program.")
parallel.waitForAll(check,keywait,dig,stats)
local mx,my = term.getCursorPos()
term.setCursorPos((mx - string.len(waittext)),my)
print("")
print(" \\e/ ")

Sorry when i missed something i am really a beginner
JokerRH #2
Posted 08 April 2013 - 09:21 AM

for i = 16, 1, -1 do
  turtle.select(i)
end
if you want to decrement write a -1 to the for loop and a turtle only has 16 slots (If i recall correct)
But why do you make it so complicated?


turtle.select(1)
while true do
  for i = 1, 64 do
    turtle.dig()
    sleep(1.5)
  end

  rs.setOutput("back", true) --"back" or whereever you have your jackedet wire
  sleep(0.2)
  rs.setOutput("back", false)
end
Amokaci #3
Posted 08 April 2013 - 09:44 AM
sry when i write it wrong

i mean every time the turtle get 64 cobble in slot 1 he send only 1 signal to the filter that he can suck the 64 cobble out

and when he get another 64 cobble then again send a only 1 redstone signal to the filter

sry my english is not the best i learnd it for 2 years ;)/>
QuantumGrav #4
Posted 08 April 2013 - 05:02 PM
The code could look like:

turtle.select(1)
while true do
turtle.dig()
if turtle.getItemCount(1) == 64 then
rs.setOutput("back", true)
sleep(0.1)
rs.setOutput("back", false)
end
end

(Sorry for no code block. I'm working from a mobile.)

That should do what you would like!

I don't know if turtles can drop stuff to a barrel, but if they can, you could just change the barrel to below the turtle, then, instead of the setOuputs and sleep, just put 'turtle.dropDown()'. That would prevent having to use the filter and make the code a tad bit more efficient.

Hope that helps!
Amokaci #5
Posted 09 April 2013 - 01:53 AM
thank you for the help now it works perfect

great community