8 posts
Posted 12 January 2013 - 06:25 PM
Hello, I am trying to program a turtle to place blocks in 64 block rows untill it runs out of blocks. I am rather new to ComputerCraft and havent had too many problems untill now. Im using functions for the first time, and everytime i run this script i dont get an error message but just "9" (no quotes) the if statements seem to work individually but it seems like the functions might be a problem?
also you might note i was trying to count the slots to watch his material level but that was the first part i took out when troubleshooting.
any help is appreciated. Thank You
slot = 1
forward = 1
back = 1
run = 1
direction = 1
while (run == 1) do
function placeforward()
if turtle.detectDown() then
turtle.digDown()
turtle.placeDown()
turtle.forward()
forward = forward + 1
else
turtle.placeDown()
turtle.forward()
forward = forward + 1
if (forward == 64) then
turtle.turnRight()
turtle.forward()
turtle.turnRight()
direction = 0
else
placeforward()
end
end
end
function placeback()
if turtle.detectDown() then
turtle.digDown()
turtle.placeDown()
turtle.forward()
back = back + 1
if (back == 64) then
turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
direction = 1
else
placeback()
end
else
turtle.placeDown()
turtle.forward()
back = back + 1
end
end
function testhandful()
if (turtle.getItemCount(slot) > 0) then
if (direction == 1) then
placeforward()
else
placeback()
end
else
run = 0
end
end
testhandful()
end
Edited on 12 January 2013 - 05:54 PM
295 posts
Location
In the TARDIS at an unknown place in time.
Posted 12 January 2013 - 06:28 PM
One thing I see is that you have only one "=" in some if statements. Make them double "="'s.
For example, change:
if forward = 64 then
To:
if forward == 64 then
"==" is a comparison and "=" is defining
8 posts
Posted 12 January 2013 - 06:31 PM
edited the code portion a bit in first post. still 9 maybe this turtle speaks german
295 posts
Location
In the TARDIS at an unknown place in time.
Posted 12 January 2013 - 06:34 PM
edited the code portion a bit any better?
Well try running it. There may be errors with how you did the turtle stuff, but I don't know since I have never worked with turtles before.
1111 posts
Location
Portland OR
Posted 12 January 2013 - 06:34 PM
You have 1 to many ends in the testhandful() function
function testhandful()
if (turtle.getItemCount() > 0) then
if (direction == 1) then
placeforward()
else
placeback()
end
else
run = 0
end --this one is extra don't need it
end
end
8 posts
Posted 12 January 2013 - 06:37 PM
Thank You. ran again nothing new is that number 9
some sort of error message?
7508 posts
Location
Australia
Posted 12 January 2013 - 06:40 PM
also this
turtle.getItemCount()
requires a parameter of the slot number
8 posts
Posted 12 January 2013 - 06:42 PM
thats what i was trying to do by declaring 'slot' and increment it. Can you use
turtle.getItemCount(slot)
thats what i had there first time around.
1111 posts
Location
Portland OR
Posted 12 January 2013 - 06:49 PM
Yes that should work. I would try again, with that change the code looks good from a syntax point of view.
8 posts
Posted 12 January 2013 - 06:50 PM
also this
turtle.getItemCount()
requires a parameter of the slot number
Actually that was it mustve been a combination of the == and that
Thank you all
Edit: Updated the code works ok wasnt looping first time so only placed one block
8 posts
Posted 12 January 2013 - 07:13 PM
okay, can someone explain these numbers to me? i changed the code to this
slot = 1
forward = 1
back = 1
run = 1
direction = 1
while (run == 1) do
function placeforward()
if turtle.detectDown() then
turtle.digDown()
turtle.placeDown()
turtle.forward()
forward = forward + 1
else
turtle.placeDown()
turtle.forward()
forward = forward + 1
if (forward == 64) then
turtle.placeDown() // edit here
turtle.turnRight()
turtle.forward()
turtle.turnRight()
direction = 0
else
placeforward()
end
end
end
function placeback()
if turtle.detectDown() then
turtle.digDown()
turtle.placeDown()
turtle.forward()
back = back + 1
if (back == 64) then
turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
direction = 1
else
placeback()
end
else
turtle.placeDown()
turtle.forward()
back = back + 1
end
end
function testhandful()
if (turtle.getItemCount(slot) > 0) then
if (direction == 1) then
placeforward()
else
placeback()
end
else //edit here to
if (slot == 16) then
if(turtle.getItemCount(slot) == 0) then
run == 0
else
slot = slot + 1
testhandful()
end //here
end
end
end
testhandful()
end
and now all i get is a '12'
I know that i will eventually figure the problem out but do these numbers help? are they just random?
Edited on 12 January 2013 - 06:17 PM
7508 posts
Location
Australia
Posted 12 January 2013 - 07:17 PM
and now all i get is a '12'
I know that i will eventually figure the problem out but do these numbers help? are they just random?
Quite often I've found random numbers are sometimes returned from a function… but not normally printed… give me a second I'll bootup Minecraft to check… so wish cc-emu did turtle emulation…
7508 posts
Location
Australia
Posted 12 January 2013 - 07:28 PM
I wasn't getting any numbers, I was only getting error messages… here is the code fixed… you had quite a few errors… including commenting, comments in lua are – not //
http://pastebin.com/uyEVHXy6
8 posts
Posted 12 January 2013 - 07:36 PM
Thank You for your help. Could it be the turtle interface? should i be in the lua prompt when trying to debug?
7508 posts
Location
Australia
Posted 12 January 2013 - 07:38 PM
no you just type the program name into the terminal and hit enter… thats where those numbers were coming from, Lua prompt, I knew I had seen them recently… lol…
8 posts
Posted 12 January 2013 - 07:41 PM
yeah just dont know what to do with them or how you got real errors like the ones that say bios something or other and gives you at least a line number lol thanks again
Edited on 12 January 2013 - 06:42 PM
1111 posts
Location
Portland OR
Posted 12 January 2013 - 07:45 PM
Some of the errors will not generate a detailed error message, sometimes you get just a single number or several numbers with no other information. Sometimes the number is the line number that is throwing the error but not always.
EDIT: Sometimes restarting your computer will help get a detailed error message when you are getting them like this.
Edited on 12 January 2013 - 06:47 PM
7508 posts
Location
Australia
Posted 12 January 2013 - 07:46 PM
Nah I think those Lua prompt ones are random, not sure tho…
But because I was running the program I was getting the proper error messages…
1111 posts
Location
Portland OR
Posted 12 January 2013 - 07:49 PM
He would have been having to do shell.run("programName") from the Lua prompt to have tried to run the program from it. I think he was running it from the normal CraftOS Shell. I have seen single number error messages from the normal prompt before.