718 posts
Location
Hawaii
Posted 07 March 2012 - 05:57 AM
I made a api and at my force function, i get a error at all turtle.*'s in my API
Force:
function force(direction)
if direction == forward then
if(turtle.detect())then
turtle.dig()
turtle.forward()
else
turtle.forward()
end
end
if direction == up then
if(turtle.detectUp())then
turtle.digUp()
turtle.up()
else
turtle.up()
end
end
if direction == down then
if(turtle.detectDown())then
turtle.digDown()
turtle.down()
else
turtle.down()
end
end
if direction == left then
turtle.turnLeft()
if(turtle.detect())then
turtle.dig()
turtle.forward()
else
turtle.forward()
end
end
if direction == right then
turtle.turnRight()
if(turtle.detect())then
turtle.dig()
turtle.forward()
else
turtle.forward()
end
end
end
Program:
tortue.force(forward)
454 posts
Location
London
Posted 07 March 2012 - 06:02 AM
I made a api and at my force function, i get a error at all turtle.*'s in my API
Force:
function force(direction)
if direction == forward then
if(turtle.detect())then
turtle.dig()
turtle.forward()
else
turtle.forward()
end
end
if direction == up then
if(turtle.detectUp())then
turtle.digUp()
turtle.up()
else
turtle.up()
end
end
if direction == down then
if(turtle.detectDown())then
turtle.digDown()
turtle.down()
else
turtle.down()
end
end
if direction == left then
turtle.turnLeft()
if(turtle.detect())then
turtle.dig()
turtle.forward()
else
turtle.forward()
end
end
if direction == right then
turtle.turnRight()
if(turtle.detect())then
turtle.dig()
turtle.forward()
else
turtle.forward()
end
end
end
Program:
tortue.force(forward)
Unless forward, left, down, etc is defined, you'll probably want them as a string:
"forward",
"left", etc.
718 posts
Location
Hawaii
Posted 07 March 2012 - 06:28 AM
I made a api and at my force function, i get a error at all turtle.*'s in my API
Force:
function force(direction)
if direction == forward then
if(turtle.detect())then
turtle.dig()
turtle.forward()
else
turtle.forward()
end
end
if direction == up then
if(turtle.detectUp())then
turtle.digUp()
turtle.up()
else
turtle.up()
end
end
if direction == down then
if(turtle.detectDown())then
turtle.digDown()
turtle.down()
else
turtle.down()
end
end
if direction == left then
turtle.turnLeft()
if(turtle.detect())then
turtle.dig()
turtle.forward()
else
turtle.forward()
end
end
if direction == right then
turtle.turnRight()
if(turtle.detect())then
turtle.dig()
turtle.forward()
else
turtle.forward()
end
end
end
Program:
tortue.force(forward)
Unless forward, left, down, etc is defined, you'll probably want them as a string:
"forward",
"left", etc.
I changed it to:
function dig()
turtle.dig()
end
function forward()
turtle.forward()
end
function up()
turtle.up()
end
function down()
turtle.down()
end
function turnLeft()
turtle.turnLeft()
end
function turnRight()
turtle.turnRight()
end
function force(direction)
if direction == forward then
if(turtle.detect())then
dig()
forward()
else
forward()
end
end
if direction == up then
if(turtle.detectUp())then
digUp()
up()
else
up()
end
end
if direction == down then
if(turtle.detectDown())then
digDown()
down()
else
down()
end
end
if direction == left then
turnLeft()
if(turtle.detect())then
dig()
forward()
else
forward()
end
end
if direction == right then
turnRight()
if(turtle.detect())then
dig()
forward()
else
forward()
end
end
end
But now everytime i say something like:
force(forward)
or any other direction, it turns left and goes straight
454 posts
Location
London
Posted 07 March 2012 - 06:42 AM
I made a api and at my force function, i get a error at all turtle.*'s in my API
Force:
function force(direction)
if direction == forward then
if(turtle.detect())then
turtle.dig()
turtle.forward()
else
turtle.forward()
end
end
if direction == up then
if(turtle.detectUp())then
turtle.digUp()
turtle.up()
else
turtle.up()
end
end
if direction == down then
if(turtle.detectDown())then
turtle.digDown()
turtle.down()
else
turtle.down()
end
end
if direction == left then
turtle.turnLeft()
if(turtle.detect())then
turtle.dig()
turtle.forward()
else
turtle.forward()
end
end
if direction == right then
turtle.turnRight()
if(turtle.detect())then
turtle.dig()
turtle.forward()
else
turtle.forward()
end
end
end
Program:
tortue.force(forward)
Unless forward, left, down, etc is defined, you'll probably want them as a string:
"forward",
"left", etc.
I changed it to:
function dig()
turtle.dig()
end
function forward()
turtle.forward()
end
function up()
turtle.up()
end
function down()
turtle.down()
end
function turnLeft()
turtle.turnLeft()
end
function turnRight()
turtle.turnRight()
end
function force(direction)
if direction == forward then
if(turtle.detect())then
dig()
forward()
else
forward()
end
end
if direction == up then
if(turtle.detectUp())then
digUp()
up()
else
up()
end
end
if direction == down then
if(turtle.detectDown())then
digDown()
down()
else
down()
end
end
if direction == left then
turnLeft()
if(turtle.detect())then
dig()
forward()
else
forward()
end
end
if direction == right then
turnRight()
if(turtle.detect())then
dig()
forward()
else
forward()
end
end
end
But now everytime i say something like:
force(forward)
or any other direction, it turns left and goes straight
Let me clarify for you:
When you type:
force(forward)
You are sending the value of the variable called
forward to
force(). Before, this was nil; and it'd do everything.
Now, you're sending the function
forward to
force. Which should work (except for the cases noted below), unless you're loading this as an API:
forward would be nil, but
yourapi.forward would be the value you're checking against.
The following if statements will always pass (assuming you're loading this as an API):
if direction == right then -- right is nil
if direction == left then -- left is nil
You need to put quotes
"str", apostrophes
'str', or doublebrackets
[[str]] around strings in Lua.
718 posts
Location
Hawaii
Posted 07 March 2012 - 06:48 AM
I made a api and at my force function, i get a error at all turtle.*'s in my API
Force:
function force(direction)
if direction == forward then
if(turtle.detect())then
turtle.dig()
turtle.forward()
else
turtle.forward()
end
end
if direction == up then
if(turtle.detectUp())then
turtle.digUp()
turtle.up()
else
turtle.up()
end
end
if direction == down then
if(turtle.detectDown())then
turtle.digDown()
turtle.down()
else
turtle.down()
end
end
if direction == left then
turtle.turnLeft()
if(turtle.detect())then
turtle.dig()
turtle.forward()
else
turtle.forward()
end
end
if direction == right then
turtle.turnRight()
if(turtle.detect())then
turtle.dig()
turtle.forward()
else
turtle.forward()
end
end
end
Program:
tortue.force(forward)
Unless forward, left, down, etc is defined, you'll probably want them as a string:
"forward",
"left", etc.
I changed it to:
function dig()
turtle.dig()
end
function forward()
turtle.forward()
end
function up()
turtle.up()
end
function down()
turtle.down()
end
function turnLeft()
turtle.turnLeft()
end
function turnRight()
turtle.turnRight()
end
function force(direction)
if direction == forward then
if(turtle.detect())then
dig()
forward()
else
forward()
end
end
if direction == up then
if(turtle.detectUp())then
digUp()
up()
else
up()
end
end
if direction == down then
if(turtle.detectDown())then
digDown()
down()
else
down()
end
end
if direction == left then
turnLeft()
if(turtle.detect())then
dig()
forward()
else
forward()
end
end
if direction == right then
turnRight()
if(turtle.detect())then
dig()
forward()
else
forward()
end
end
end
But now everytime i say something like:
force(forward)
or any other direction, it turns left and goes straight
Let me clarify for you:
When you type:
force(forward)
You are sending the value of the variable called
forward to
force(). Before, this was nil; and it'd do everything.
Now, you're sending the function
forward to
force. Which should work (except for the cases noted below), unless you're loading this as an API:
forward would be nil, but
yourapi.forward would be the value you're checking against.
The following if statements will always pass (assuming you're loading this as an API):
if direction == right then -- right is nil
if direction == left then -- left is nil
You need to put quotes
"str", apostrophes
'str', or doublebrackets
[[str]] around strings in Lua.
thanks, it worked