Jump to content




Program error.

turtle help

75 replies to this topic

#1 detsuo04

  • Members
  • 35 posts

Posted 13 January 2013 - 10:48 PM

Ok so i started messing with computer craft today and this is my result so far. However Im getting an error. string miner :93: "=" expected, or something to that effect.
The first chunk just deals with its initial startup and communication. all that is tested and works.
i have gone over the code several times but im not sure whats wrong. If anyone could give it a look i would apreciate it.
Thanks for the help.

rednet.open("right")
rn = rednet.send
fx = turtle.getItemCount(16)
a = fx - 1
sleep(1)
rn (base , "Connection established")
sleep(1)
rn (base , "getting fuel level")
sleep(1)
turtle.getFuelLevel()
local f = turtle.getFuelLevel()
sleep(1)
rn (base , "Current fuel level is "..f.."" )
sleep(1)
if f < 100 then
  turtle.getItemCount(16)
  rn (base , "current coal stack is")
  turtle.select(16)
  turtle.refuel(a)
    else
    rn (base , "Fuel levels are acceptable")
    sleep(1)
  end
sleep(1)
rn (base , "getting coal count")
turtle.getItemCount(16)
sleep(1)
rn (base, "I have "..fx.." Coal")
sleep(1)
if fx < 64 then
  rn (base, "DANGER! Coal is low")
  os.reboot() 
  else
    rn (base, "Coal storage is full")
    sleep(2)
	  end
sleep(1)
rn (base , "comencing program")
--=======comence mining=======--
td = turtle.dig
tm = turtle.move
tc = turtle.detect
--===========fuel=============--
turtle.getFuelLevel()
  if f < z + 10 then
  rn (base , "Danger! fuel levels low.")
  turtle.select(16)
  turtle.refuel(a)
  turtle.getFuelLevel()
    if f < z + 10 then
    rn (base , "Insuficient Coal, Returning.")
    home()
    else
    end
  else
  end
--=======return code==========--
function home()
  tcUp(z + 2)
  rn (base , "Mining Operation finished")
  os.shutdown()
  end
--============value===========--
function value()
if turtle.detect() == false
then return false
end
  for i = 1,3 do
    turtle.select(i)
    if turtle.compare() then
    return false
    else
    return true
    end
  end
--============walls===========--
function walls()
  for j = 1,4 do
    if value() then
    td()
    rn (base, "ORE!")
	  else
	  turtle.turn("right")
	  end
end
--=============home===========--
function home()
tmUp(z)
rn (base , "Done, ready for pickup")
os.shutdown

--===========Dig Code=========--
function mine()
fuel()
  tcDown()
   if true then
   tdDown()
   tcDown()
    if true then
    rn (base , "I hit bedrock, Returning")
    home()
	  else
	  tmDown()
	  walls()
	  z = z + 1
	  else
	   tmDown()
	   walls()
	   z = z + 1
	   end
   end
   --===========start=========--
   while true do
   mine()
   end
  


#2 crazyguymgd

  • Members
  • 139 posts
  • LocationUSA

Posted 13 January 2013 - 10:59 PM

you're missing ends to a lot of your functions. The one's I found were to value(), walls(), home(), and mine().
Also, turtle.turnRight() not turtle.turn("right")
In your home() function you use os.shutdown instead of os.shutdown()...
and maybe some other things. try going through your code and seeing if you can find any more problems :P debugging code is like a game, the more problems you find, the more points you get. so far, I'm winning.

#3 detsuo04

  • Members
  • 35 posts

Posted 13 January 2013 - 11:04 PM

HA ok ill fix the errors and get back to you.

actually im a little fuzzy on what denotes the need for end

im not sure how many to put

#4 crazyguymgd

  • Members
  • 139 posts
  • LocationUSA

Posted 13 January 2013 - 11:12 PM

examples:

function foo()
  ... 
end

if condition then
   ...
end

if condition then
   if condition2 then
      ...
   end
else
  ...
end

while something do
  ...
end

for x = 1, n do
  ...
end

and so on

#5 detsuo04

  • Members
  • 35 posts

Posted 13 January 2013 - 11:21 PM

ok so i added the ends and fixed the errors you mentioned now im getting a eof error at 56? which i suspect has something to do with that else end pile there. but im not sure whats wrong with it
rednet.open("right")
rn = rednet.send
fx = turtle.getItemCount(16)
a = fx - 1
sleep(1)
rn (base , "Connection established")
sleep(1)
rn (base , "getting fuel level")
sleep(1)
turtle.getFuelLevel()
local f = turtle.getFuelLevel()
sleep(1)
rn (base , "Current fuel level is "..f.."" )
sleep(1)
if f < 100 then
  turtle.getItemCount(16)
  rn (base , "current coal stack is")
  turtle.select(16)
  turtle.refuel(a)
    else
    rn (base , "Fuel levels are acceptable")
    sleep(1)
  end
sleep(1)
rn (base , "getting coal count")
turtle.getItemCount(16)
sleep(1)
rn (base, "I have "..fx.." Coal")
sleep(1)
if fx < 64 then
  rn (base, "DANGER! Coal is low")
  os.reboot() 
  else
    rn (base, "Coal storage is full")
    sleep(2)
	  end
sleep(1)
rn (base , "comencing program")
--=======comence mining=======--
td = turtle.dig
tm = turtle.move
tc = turtle.detect
--===========fuel=============--
turtle.getFuelLevel()
  if f < z + 10 then
  rn (base , "Danger! fuel levels low.")
  turtle.select(16)
  turtle.refuel(a)
  turtle.getFuelLevel()
    if f < z + 10 then
    rn (base , "Insuficient Coal, Returning.")
    home()
    end
    else
    end
  else
end
--=======return code==========--
function home()
  tcUp(z + 2)
  rn (base , "Mining Operation finished")
  os.shutdown()
end
--============value===========--
function value()
if turtle.detect() == false
then return false
end
  for i = 1,3 do
    turtle.select(i)
    if turtle.compare() then
    return false
    end
    else
    return true
    end
end
--============walls===========--
function walls()
  for j = 1,4 do
    if value() then
    td()
    rn (base, "ORE!")
    end
	  else
	  turtle.turnright()
	  end
  end
end
--=============home===========--
function home()
tmUp(z)
rn (base , "Done, ready for pickup")
os.shutdown()
end

--===========Dig Code=========--
function mine()
fuel()
  tcDown()
   if true then
   tdDown()
   tcDown()
    if true then
    rn (base , "I hit bedrock, Returning")
    home()
    end
	  else
	  tmDown()
	  walls()
	  z == z + 1
	  end
	  else
	   tmDown()
	   walls()
	   z == z + 1
	   end
   end
   --===========start=========--
   while true do
   mine()
   end
  


#6 crazyguymgd

  • Members
  • 139 posts
  • LocationUSA

Posted 13 January 2013 - 11:29 PM

well the extra else's aren't necessary so did you try just getting rid of them? also, there are a couple of places where you have
if condition then
   ...
end
else
  ...
end

that first end isn't necessary. so you can find those and get rid of them too.

#7 detsuo04

  • Members
  • 35 posts

Posted 13 January 2013 - 11:38 PM

just to clerify

if condition then
if condition then
....
end
else
end

right?

#8 crazyguymgd

  • Members
  • 139 posts
  • LocationUSA

Posted 13 January 2013 - 11:42 PM

so nested ifs?

if condition then
  if condition then
    -- do something
  end
else
    -- do something else
end

but you only need that else if you're actually going to do something else. otherwise just an end.
if that's not clear i'm sure there's a wikipedia page that explains ifs and elses better than I can. or someone else on here.

#9 detsuo04

  • Members
  • 35 posts

Posted 13 January 2013 - 11:58 PM

awsome you are mega helpful. ok so i have finished the edits and the program returns no errors. however it ends without doing anything. kindof confused on this since its giving me no feed back. right now im looking over my dig function for a reason

#10 crazyguymgd

  • Members
  • 139 posts
  • LocationUSA

Posted 14 January 2013 - 12:01 AM

it often helps to put some debugging print statements in this situation. also, make sure you're actually calling the main function after all these edits. sometimes that could get missed.

#11 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 14 January 2013 - 12:01 AM

Conditionals are definitely a very important part of programming that everyone needs to know... that being said here goes...

Explaination of if's
Spoiler

Off the top of my head I think I have covered everything, I hope I'm not forgetting anything and that it all makes sense, it made sense in my head ;)

EDIT: Oops just remembered something... editing


Pro tip:
Spoiler
ok now I think thats it ;)

Edited by TheOriginalBIT, 14 January 2013 - 12:07 AM.


#12 detsuo04

  • Members
  • 35 posts

Posted 14 January 2013 - 12:15 AM

frustration is hitting an all time high. i copy the program from my computer to a disk. then run it to the turtle and copy from disk to turtle No such file.
so i go back and try the copy again. file already exists. i have gone back and forth ten times with different disks trying to preform this simple operation that i have done 100 times already. BLARG coding is killer

Edit ok i got the disk to work again. not sure what happened there

code still doing nothing though. i am going to spend some time and go over it again.

Here it is as it stands incase somebody catches something i missed.. Once agfain thanks for all your help guys
rednet.open("right")
rn = rednet.send
fx = turtle.getItemCount(16)
a = fx - 1
sleep(1)
rn (base , "Connection established")
sleep(1)
rn (base , "getting fuel level")
sleep(1)
turtle.getFuelLevel()
local f = turtle.getFuelLevel()
sleep(1)
rn (base , "Current fuel level is "..f.."" )
sleep(1)
if f < 100 then
  turtle.getItemCount(16)
  rn (base , "current coal stack is")
  turtle.select(16)
  turtle.refuel(a)
    else
    rn (base , "Fuel levels are acceptable")
    sleep(1)
  end
sleep(1)
rn (base , "getting coal count")
turtle.getItemCount(16)
sleep(1)
rn (base, "I have "..fx.." Coal")
sleep(1)
if fx < 64 then
  rn (base, "DANGER! Coal is low")
  os.reboot() 
  else
    rn (base, "Coal storage is full")
    sleep(2)
	  end
sleep(1)
rn (base , "comencing program")
--=======comence mining=======--
td = turtle.dig
tm = turtle.move
tc = turtle.detect
z = 0
--===========fuel=============--
function fuel()
print("1")
turtle.getFuelLevel()
  if f < z + 10 then
  rn (base , "Danger! fuel levels low.")
  turtle.select(16)
  turtle.refuel(a)
  turtle.getFuelLevel()
    if f < z + 10 then
    rn (base , "Insuficient Coal, Returning.")
    home()
	 else
	 end
end
end
--=======return code==========--
function home()
  tcUp(z + 2)
  rn (base , "Mining Operation finished")
  os.shutdown()
end
--============value===========--
function value()
if turtle.detect() == false
then return false
end
  for i = 1,3 do
    turtle.select(i)
    if turtle.compare() then
    return false
    else
    return true
    end
end
--============walls===========--
function walls()
  for j = 1,4 do
    if value() then
    td()
    rn (base, "ORE!")
	  else
	  turtle.turnright()
	  end
  end
end
--=============home===========--
function home()
tmUp(z)
rn (base , "Done, ready for pickup")
os.shutdown()
end

--===========Dig Code=========--
function mine()
print("1")
fuel()
print("2")
  tcDown()
   if true then
   tdDown()
   tcDown()
   print("3")
    if true then
    rn (base , "I hit bedrock, Returning")
    home()
	  else
	  tmDown()
	  print("4")
	  walls()
	  print("5")
	  z = z + 1
	  end
	  else
	   tmDown()
	   walls()
	   z = z + 1
	   end
   end
   --===========start=========--
   while true do
   mine()
   end
end  


#13 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 14 January 2013 - 12:16 AM

are you typing in the copy correct? i.e from the disk to the root of the turtle...

#14 crazyguymgd

  • Members
  • 139 posts
  • LocationUSA

Posted 14 January 2013 - 12:23 AM

your while true do mine() end needs to be outside of the mine() function.

#15 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 14 January 2013 - 12:24 AM

View Postcrazyguymgd, on 14 January 2013 - 12:23 AM, said:

your while true do mine() end needs to be outside of the mine() function.
As a side note here, you should never call a function recursively unless you have some way for it to return back down the function tree... or else you will get a stack overflow error as your program has run out of space...

#16 detsuo04

  • Members
  • 35 posts

Posted 14 January 2013 - 12:30 AM

i moved some ends around to acomodate that now its

end
end
end
start
while true do mine()
end

though still dosnt move or return errors

not sure what you mean.
you mean i shouldnt loop the function mine() ?

#17 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 14 January 2013 - 12:32 AM

if true then else will NEVER do the else... true can never be false...

#18 detsuo04

  • Members
  • 35 posts

Posted 14 January 2013 - 12:34 AM

huh? where did i do that?

#19 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 14 January 2013 - 12:41 AM

ok I've gone and commented your code with all the mistakes that you have made ( hope i didn't miss any )

http://pastebin.com/eCHabxgj

#20 crazyguymgd

  • Members
  • 139 posts
  • LocationUSA

Posted 14 January 2013 - 12:45 AM

View PostTheOriginalBIT, on 14 January 2013 - 12:41 AM, said:

ok I've gone and commented your code with all the mistakes that you have made ( hope i didn't miss any )

http://pastebin.com/eCHabxgj

I was just getting into doing this as well...





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users