191 posts
Posted 04 March 2013 - 03:18 AM
Title: Error- whats wrong with my code?
Spoiler
function refuel()
while turtle.getFuelLevel() < 5000 do
refuel()
end
end
refuel()
function forw(times)
for i = 1, times do
turtle.dig()
turtle.forward()
refuel()
end
end
function left(times)
for i = 1, times do
turtle.turnLeft()
refuel()
end
end
function right(times)
for i = 1, times do
turtle.turnRight()
refuel()
end
end
counter = 0
counter2= 1
for i = 1, 66 do
for i = 1, 7 do
forw(15)
left(1)
forw(1)
left(1)
forw(15)
right(1)
forw(1)
right(1)
end
forw(15)
left(1)
forw(1)
left(1)
forw(15)
left(1)
forw(15)
left(1)
counter=counter+1
if turtle.getItemCount(16) > 1 then
for i = 1, counter do
turtle.up()
refuel()
end
right(2)
while counter2<16 do
turtle.select(counter2)
turtle.drop()
counter2=counter2 + 1
end
left(2)
for i = 1, counter do
turtle.down()
end
end
end
for i = 1, 66 do
turtle.up()
refuel()
end
its supposed to quarry out a 16 by 16 area, dumping all of its items when full
When i run the program i get "java.lang.ArrayIndexOutOfBoundsExeption"
HEEELP D:
8543 posts
Posted 04 March 2013 - 07:04 AM
Split into new topic.
1852 posts
Location
Sweden
Posted 04 March 2013 - 07:36 AM
I was getting the same error one time and someone said to me that it was because
I used too many functions, And well… You use alot.
758 posts
Location
Budapest, Hungary
Posted 04 March 2013 - 07:39 AM
refuel calls itself. And turtle.refuel is nowhere… That's the problem…
I mean
function refuel()
while turtle.getFuelLevel() < 5000 do
turtle.refuel()
end
end
1852 posts
Location
Sweden
Posted 04 March 2013 - 07:41 AM
And why do you do this?
function refuel()
while turtle.getFuelLevel() < 5000 do
refuel() --You are calling the fuction in itself... Why? Did you mean to use the turtle.refuel()
end
end
--[[
This just repeats the function 'refuel()' over and
over if the fuel level isn't equal or more than 5000
Try to use 'turtle.refuel()' instead of 'refuel()'
]]--
EDIT: Damn got ninja'd
191 posts
Posted 04 March 2013 - 07:54 AM
Wow, THANKS LBPhacker (it wasn't inteded ;D)
1511 posts
Location
Pennsylvania
Posted 04 March 2013 - 02:04 PM
And why do you do this?
function refuel()
while turtle.getFuelLevel() < 5000 do
refuel() --You are calling the fuction in itself... Why? Did you mean to use the turtle.refuel()
end
end
--[[
This just repeats the function 'refuel()' over and
over if the fuel level isn't equal or more than 5000
Try to use 'turtle.refuel()' instead of 'refuel()'
]]--
EDIT: Damn got ninja'd
Just for future reference, what you are doing within the function is not by any means "proper". You are looping a check for a fuel level lower than 5000 which will sooner or later return an error (Too long without yielding). Also, you say it checks for a fuel level less than or equal to. Then why do you say (< 5000) when it should, in reality, be (<= 5000).
7508 posts
Location
Australia
Posted 04 March 2013 - 02:06 PM
sooner or later return an error (Too long without yielding)
Actually as it is in OP it would say '
java.lang.ArrayIndexOutOfBoundsExeption' before it would error to yielding as the program stack fills up quicker than the 10 seconds.
1511 posts
Location
Pennsylvania
Posted 04 March 2013 - 02:55 PM
sooner or later return an error (Too long without yielding)
Actually as it is in OP it would say '
java.lang.ArrayIndexOutOfBoundsExeption' before it would error to yielding as the program stack fills up quicker than the 10 seconds.
Hmm, guess you're right again… Either way they are both a pain ( That's something I think we can both agree on ;)/> )
EDIT: I don't think
Semi-Proffesional ComputerCrafter fits your knowledge (One more thing we can agree on)