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

[ERROR] cft:12: attempt to call number

Started by Mtdj2, 04 August 2012 - 04:36 PM
Mtdj2 #1
Posted 04 August 2012 - 06:36 PM
Hi there. I know quite a bit of lua, so now i made a huge project including the new crafting turtle. (You might be able to guess what)
I am making a turtle captable of crafting all craftable vanilla items and blocks. I have very good ideas at how, and i've made some code already.

Code:

--Easier for me to program.
local function f() turtle.forward() end
local function b() turtle.back() end
local function l() turtle.turnLeft() end
local function r() turtle.turnRight() end
local function u() turtle.up() end
local function d() turtle.down() end
local function sel(slot) turtle.select(slot) end
local function c(num) turtle.craft(num) end
local function s() turtle.suck() end

function stone(s) f() f() l() f() f() f() sel(s) s() b() b() b() r() b() b() end --Line disfunctioning.
function wood(s) f() f() l() f() f() f() u() sel(s) s() d() b() b() b() r() b() b() end
function piston(s) for i=1,6 do f() end l() sel(s) s() r() for i=1,6 do b() end end
stone(1)
stone(5)
c(1)

And a little screenie:


Yea, turtle has to move over, pick up a stack of stone, return, do the same again and craft it.
Hope all of this is understandable, readable and explainable.
KingMachine #2
Posted 04 August 2012 - 06:46 PM
My guess is that it's not liking selecting the slot that it already has selected. But I don't know much about turtles. Try commenting out stone(1) and just let stone(5) run instead. If that works then I'm right. If not, try renaming your function input decimal to q or something other than s. I think having a function named the same as a variable can't be good for it.
Lyqyd #3
Posted 04 August 2012 - 06:50 PM

local function s() turtle.suck() end

function stone(s) f() f() l() f() f() f() sel(s) s() b() b() b() r() b() b() end

You accept input into the function in the variable 's', which will overwrite the contents of the 's' function, at least in the scope of this function. So then you're trying to call as a function whatever number you passed to this function. You can't use the same variable name for two different things and expect it to magically know which you meant.
Mtdj2 #4
Posted 06 August 2012 - 03:37 PM
Ok, thanks for the feedback. It works perfectly, and i learned something from it. Thanks.
KingMachine #5
Posted 08 August 2012 - 07:05 AM
So I was right then. Oh goody.
KaoS #6
Posted 08 August 2012 - 07:58 AM
also, why create a function with a function in it, you could just

s=turtle.suck
b=turtle.back

etc