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

Code not working

Started by samken600, 21 May 2013 - 03:30 PM
samken600 #1
Posted 21 May 2013 - 05:30 PM
Hello
I have been trying to write a code that places the block in front of it, empties its inventory and then picks the block up again when it is not receiving a redstone signal, which is pulsed by a computer. I also want it not to bug out if I restart it as I believe I have done. I wrote this, probably not in the most efficient way, but it sometimes bugs out and instead of collecting the original item, it has a different item in the turtle. This only happens sometimes, normally after I restart the server, even though I do it at the end of the turtles cycle with the computer off.

http://pastebin.com/Q27M0qWC - Turtle code
http://pastebin.com/y0mYPshE - Computer code

If you have any suggestions that could improve my code by stopping this bug and making it more efficient it would be most appreciated
Thanks
- samken600
Lyqyd #2
Posted 22 May 2013 - 01:43 AM
Split into new topic.
Zudo #3
Posted 22 May 2013 - 03:24 AM
I can't see anything wrong…?
plazter #4
Posted 22 May 2013 - 08:53 AM
uhm, im not sure what you want you'r program to do but i've made a code yesterday that empties it inventory, it might be able to use it in this way u wish


function Drop() -- u can allways rename this :D/>/>/>/>/>/>/>/>/>
  for i = 1,16 do
   if turtle.getItemCount(i) > 0 do
	turtle.select(i)
   turtle.drop()
  end
end
end
---- MAIN PROGRAM -----
while true do
while rs.getInput("back") do
  Drop()
sleep(4)
end

while not rs.getInput("back") do
  sleep(3)
end
end

Ain't sure this works, but i made it something like that :)/>
Hope it works, and helps :)/>

EDIT: This is semi working, tho there is a too long without yielding im working on right now! :)/> Have fun!
EDIT2: http://pastebin.com/0RGsyA0j That should work, in princip, tho aint sure :)/>
CtrlAltElite #5
Posted 22 May 2013 - 10:44 AM
Hello
I have been trying to write a code that places the block in front of it, empties its inventory and then picks the block up again when it is not receiving a redstone signal, which is pulsed by a computer. I also want it not to bug out if I restart it as I believe I have done. I wrote this, probably not in the most efficient way, but it sometimes bugs out and instead of collecting the original item, it has a different item in the turtle. This only happens sometimes, normally after I restart the server, even though I do it at the end of the turtles cycle with the computer off.

http://pastebin.com/Q27M0qWC - Turtle code
http://pastebin.com/y0mYPshE - Computer code

If you have any suggestions that could improve my code by stopping this bug and making it more efficient it would be most appreciated
Thanks
- samken600


if it is stopping when you restart the server, then you have to make it the startup program. Or else you will have to re-type the program name into the turtle and into PC every time you relog. ~CtrlAltElite
samken600 #6
Posted 22 May 2013 - 01:24 PM
I have made a startup program that runs shell.run("dodig")
And plazter, I'm trying your code out now and see if it fixes the bug. Yours is soo much more efficient. By the way, if statements use then, not do
plazter #7
Posted 22 May 2013 - 02:59 PM
I have made a startup program that runs shell.run("dodig")
And plazter, I'm trying your code out now and see if it fixes the bug. Yours is soo much more efficient. By the way, if statements use then, not do

i noticed, played with the code, when i realised that it was a similar code i had issue with last night, tho got it working for my purpose :)/>
samken600 #8
Posted 22 May 2013 - 06:18 PM
OK so I updated the code and now it is this:

It seemed to be working at first but then it mixed up dirt and cobble with the mining well, which is the bug I was experiencing in the first place, so it turns out it didn't fix it


function Drop()
  for i = 2,16 do
   if turtle.getItemCount(i) > 0 then
		turtle.select(i)
   turtle.dropUp()
  end
end
end
while true do
sleep(1)
if redstone.getInput("back") == false then
turtle.select(1)
turtle.place()
os.sleep(26)
turtle.select(1)
turtle.dropUp()
turtle.dig()
sleep(1)
Drop()
end
end


while true do
redstone.setOutput("back", true)
redstone.setOutput("left", false)
rs.setOutput("top", true)
if redstone.getInput("front") == true then
rs.setOutput("top", false)
redstone.setOutput("left", true)
sleep(2)
rs.setOutput("left", false)
rs.setOutput("bottom", true)
sleep(1)
rs.setOutput("bottom", false)
sleep(1)
redstone.setOutput("back", false)
sleep(1)
redstone.setOutput("back", true)
redstone.setOutput("right", false)
sleep(30)
else
sleep(0)
rs.setOutput("top", true)
end
end

Does anyone have any idea what I am doing wrong? I can't see any problems. Is it just a bug with ComputerCraft?
If it helps, I can PM you the server IP (it's my server by the way) and you can have a look at it yourslef
samken600 #9
Posted 23 May 2013 - 01:01 PM
I have just tried the code again and it randomly bugs out one turtle at least one every other cycle
plazter #10
Posted 23 May 2013 - 05:51 PM
OK so I updated the code and now it is this:

It seemed to be working at first but then it mixed up dirt and cobble with the mining well, which is the bug I was experiencing in the first place, so it turns out it didn't fix it


function Drop()
  for i = 2,16 do
   if turtle.getItemCount(i) > 0 then
		turtle.select(i)
   turtle.dropUp()
  end
end
end
while true do
sleep(1)
if redstone.getInput("back") == false then
turtle.select(1)
turtle.place()
os.sleep(26)
turtle.select(1)
turtle.dropUp()
turtle.dig()
sleep(1)
Drop()
end
end


while true do
redstone.setOutput("back", true)
redstone.setOutput("left", false)
rs.setOutput("top", true)
if redstone.getInput("front") == true then
rs.setOutput("top", false)
redstone.setOutput("left", true)
sleep(2)
rs.setOutput("left", false)
rs.setOutput("bottom", true)
sleep(1)
rs.setOutput("bottom", false)
sleep(1)
redstone.setOutput("back", false)
sleep(1)
redstone.setOutput("back", true)
redstone.setOutput("right", false)
sleep(30)
else
sleep(0)
rs.setOutput("top", true)
end
end

Does anyone have any idea what I am doing wrong? I can't see any problems. Is it just a bug with ComputerCraft?
If it helps, I can PM you the server IP (it's my server by the way) and you can have a look at it yourslef

Hmm… i dont see any issue ;s, i might try play with your code, when the server i'm playing on is working :D/>
samken600 #11
Posted 23 May 2013 - 06:32 PM
OK. I have been doing some research and could find nothing, so I screwed it all and re wrote the code using rednet. I'll post the code here and if you have any surgestions to make it better please post. I think it's working properly now so it's just improving the code:
Turtle Code

function deploy()
   turtle.select(1)
   turtle.place()
end
function clearInv()
    for i = 1,16 do
	    if turtle.getItemCount(i) > 0 then
		    turtle.select(i)
		    turtle.dropUp()
	    end
   turtle.select(1)
end
end
function retrive()
   turtle.select(1)
   while turtle.getItemCount(1) > 0 do
	   turtle.dropUp()
    sleep(5)
end
    turtle.dig()
end
deploy()
sleep(17.5)
clearInv()
retrive()
Turtle Code Rednet Reciever

rednet.open("right")
while true do
    senderId, message, distance = rednet.receive()
print(message)
shell.run(message)
end
Computer Code

function pulse(side)
    rs.setOutput(side, true)
    sleep(0.4)
    rs.setOutput(side, false)
    sleep(0.4)
end
function state(tf)
    rs.setOutput("top", tf)
end
function move(no)
    for i = 1, no do
	    pulse("left")
	 pulse("bottom")
end
end
function rednetSend()
    rednet.open("right")
    for i = 7, 14 do
	 rednet.send(i, "cycle")
end
end
 
while true do
    if rs.getInput("front") == true then
	 sleep(0)
	    state(false)
	 move(1)
	 rednetSend()
  sleep(19)
    else
	 sleep(0)
	 state(true)
end
end