41 posts
Posted 28 June 2013 - 11:54 AM
I get the error: "for limit must be a number"
when I run this:
local function GetDrop()
if bm == true then
Drop = 14
elseif bm == false then
Drop = 15
else
DropInvalid()
end
toDrop = tonumber(Drop)
end
local function Drop()
for i = 2,toDrop do
turtle.select(i)
turtle.dropDown()
end
end
I already use tonumber() but it still says that.
1114 posts
Location
UK
Posted 28 June 2013 - 12:04 PM
Why are you using tonumber? Your Drop variable already is a number!
41 posts
Posted 28 June 2013 - 12:06 PM
I just tried it with tonumber to see if it works with this. But even without it gives me the error. :(/>
871 posts
Posted 28 June 2013 - 12:13 PM
running that will do absolutely nothing, because the code you shows us only declares functions, never calls them.
Please, everyone, post entire programs that don't work, not just the tiny snippets you think are the problem. If you knew what the problem was, you wouldn't be here asking for help!
If the program is too long, try taking the bits and running them in a separate, smaller program yourself, it can make it a lot easier to identify where the problems are.
That said, you're using Drop as a number in GetDrop, which means if you had called GetDrop first (as it appears you should, since GetDrop assigns toDrop), then the Drop function may well have been overwritten with the number 14 or 15, so an attempt to call Drop() will get you an attempt to call nil error.
41 posts
Posted 28 June 2013 - 12:26 PM
Ok, I now just used print(Drop) and got nil. For some reason it didn't set Drop.
Fixed it now
41 posts
Posted 28 June 2013 - 03:26 PM
Poorly the error is back again. The code:
local function ConvertInput()
if bm == "y" or bm == "yes" then
bm = true
Drop = 14
elseif bm == "n" or bm == "no" then
bm = false
Drop = 15
end
bm1 = tostring(bm)
print("bm = " .. bm1)
print("Drop =" .. Drop)
end
Before this is a read() command: bm = read()
The last three things are for testing, but shows everything is fine. The next thing:
local function Drop()
for i = 2,Drop do
turtle.select(i)
turtle.dropDown()
end
end
(They run in that order. Between is nothing that modifies this)
Still getting the "'for' limit must be a number" error
I also set a print(Drop) before the Drop() function. It shows 14 or 15 like it should.
If you need the whole code for some reason:
http://pastebin.com/pqz9MAMv (Waring: That's a big mess. Also it doesn't work yet, so don't run it)
I hope this time it's clear and that someone knows why this happens.
220 posts
Location
Germany
Posted 28 June 2013 - 03:47 PM
You have called a var "Drop", you can't aditionally call function "Drop". You could call it "dropItem" or something.
41 posts
Posted 28 June 2013 - 04:01 PM
Ohh.. ok.
This means if I have a function Drop(), the name Drop is reserved and can't be used as placeholder.
Good to know. Thank you!
2005 posts
Posted 28 June 2013 - 07:23 PM
Hey, +1 GopherAtl for spotting that too! And as kinda an apology for not noticing.