5 posts
Posted 26 June 2013 - 01:22 PM
Hi there,
Thanks for the brilliantly useful forum, it's been of great help! But it's that time, after staring for hours, I have to give in and ask for a second set of far more experienced eyes to look over my code. Here's the code:
http://pastebin.com/nNiaKLUWPurpose: It mines a tunnel which it then lines, it also places torches and chests as it goes along.
Problem: It successfully asks for the height, then the width, it then asks the user to press enter. It's after this I get the error, after the press of enter but before it digs anything or moves.
The error I'm receiving is "turtle:18: Expected number"
Any help would be greatly appreciated. I only started coding Lua today, so please don't be too hard on me :P/>/>
Thanks in advance,
Husky
8543 posts
Posted 26 June 2013 - 01:27 PM
Split into new topic.
1522 posts
Location
The Netherlands
Posted 26 June 2013 - 01:43 PM
There is no way this is the original code. Please give us the
exact code you are using. Otherwise we are not able to help you. How I concluded this is not the original code, is in this way:
SpaceWithChest=4
Here is nothing wrong. However, it says turtle:18:, so you called a turtle function or you have named your program turtle.
And if you are doing something that needs an integer parameter, and you use read to get that number. Use this snippet instead, this actually makes the string, what the read function returns, a number.
local number = nil
repeat
number = tonumber(read())
until number
print(type(number))
number = read()
print(type(number))
8543 posts
Posted 26 June 2013 - 01:45 PM
Or the error is originating in the turtle API. Check line 18. If it has an error() call, try adding a second argument to it, using the number 2.
5 posts
Posted 26 June 2013 - 01:50 PM
There is no way this is the original code. Please give us the
exact code you are using. Otherwise we are not able to help you. How I concluded this is not the original code, is in this way:
SpaceWithChest=4
Here is nothing wrong. However, it says turtle:18:, so you called a turtle function or you have named your program turtle.
And if you are doing something that needs an integer parameter, and you use read to get that number. Use this snippet instead, this actually makes the string, what the read function returns, a number.
local number = nil
repeat
number = tonumber(read())
until number
print(type(number))
number = read()
print(type(number))
This is it. :blink:/>
I run on the turtle:
pastebin get
nNiaKLUW tunnel
i've never named it "turtle" when I've loaded it, and I've used various name when putting it into the turtle.
Or the error is originating in the turtle API. Check line 18. If it has an error() call, try adding a second argument to it, using the number 2.
Hmm, that's a bit over my head at my current level. I'll do some more reading to figure it out.
Thanks for the help guys!
1522 posts
Location
The Netherlands
Posted 26 June 2013 - 01:53 PM
Or the error is originating in the turtle API. Check line 18. If it has an error() call, try adding a second argument to it, using the number 2.
Here is nothing wrong. However, it says turtle:18:, so you called a turtle function or you have named your program turtle.
I did say it, only not directly :P/>
5 posts
Posted 26 June 2013 - 01:59 PM
Ok, so I scratched my head a bit, then went fishing in the game files and found the turtle API in
computercraft.zip\lua\rom\apis\turtlehere are lines 1 through 24, 18 I've put —————— after
if not turtle then
error( "Cannot load turtle API on computer" )
end
native = turtle.native or turtle
local function waitForResponse( _id )
local event, responseID, success
while event ~= "turtle_response" or responseID ~= _id do
event, responseID, success = os.pullEvent( "turtle_response" )
end
return success
end
local function wrap( _sCommand )
return function( ... )
local id = native[_sCommand]( ... ) ----------------------
if id == -1 then
return false
end
return waitForResponse( id )
end
end
8543 posts
Posted 26 June 2013 - 02:05 PM
Here is a quick script that should help debug what's going on. Save it as debug, then run your program like usual, except put debug in front of the command. For example, if you usually run "tunnel 2 3", you'd run "debug tunnel 2 3" instead.
Edit: never mind, I see your above post, and there is no error call there. This script will not help.
local linesTable = {}
local handle = io.open("rom/apis/turtle", "r")
if handle then
for line in handle:lines() do
if string.match(line, "^%s*(error)")
table.insert(linesTable, line)) then
line = string.match(line, "(.-)%)$")..", 2)"
end
handle:close()
else
print("Couldn't open turtle API!")
return
end
local wHandle = io.open("turtle", "w")
if wHandle then
for i = 1, #linesTable do
wHandle:write(linesTable[i].."\n")
end
wHandle:close()
else
print("Couldn't write file!")
return
end
os.unloadAPI("turtle")
if not os.loadAPI("turtle") then
print("API failed to load!")
os.loadAPI("rom/apis/turtle")
return
end
shell.run(...)
os.unloadAPI("turtle")
os.loadAPI("rom/apis/turtle")
5 posts
Posted 26 June 2013 - 02:21 PM
With nothing to lose I did it anyway haha
EDIT: Going to go through the code section at a time commenting things out
8543 posts
Posted 26 June 2013 - 03:14 PM
Instead of commenting out, try adding debug prints to narrow down where it is/what it's doing when it fails.
5 posts
Posted 26 June 2013 - 03:46 PM
Instead of commenting out, try adding debug prints to narrow down where it is/what it's doing when it fails.
Thanks, exactly what I'm doing now :)/>
EDIT: Got it!!!! After much searching.
The section where I check if there are any more blocks in it's inventory that are the same as the current fill block.
--cycle round each inventory slot
for BlockCheckCounter=FirstEmptySlot,LastEmptySlot do
--select the current slot for this cycle
turtle.select(BlockCheckCounter)
--compare the selected block to the fill block
if turtle.compareTo(SpaceWithBlock)==true then
--if there is a match then use it to refill fill block
turtle.transferTo(SpaceWithBlock)
end
end
I had "SpaceWithBlocks" as opposed to "SpaceWithBlock"
My head hurts now :wacko:/>
Thank you guys for all the help. I know it's not an exciting bit of code, but you took the time to help anyway. Big thumps up
Husky