Jump to content




Problem with (if then) or Turtle(api)

help lua turtle

3 replies to this topic

#1 BaneIronhand

  • New Members
  • 2 posts
  • LocationSaskatchewan

Posted 20 December 2012 - 06:43 PM

Trying to write a simple mining program to tunnel down a set distance then move over and come back then dump etc. (my second program ever)

Wrote this function to handle refueling.

function juice()

	  turtle.select(1)

	  if turtle.getitemCount(1) < 1 then
		 print ("Feed Me")
		 repeat
		   sleep (5)
		 until turtle.getitemCount(1) > 10
	  end

	  if turtle.getFuelLevel() < 5 then
		 repeat
			print ("Fueling Standby")	
			turtle.select(1)
			turtle.refuel(1)
		 until turtle.getFuelLevel() > 50
	  end

end

I am getting an "attemp to call nil" error on the first "if" statement. (should be coloured red) My problem is that I wrote the bottom "If" statement (coloured blue) for my first program and it works just fine. My question is do i have a problem with the lua syntax or the Turtle (api) or something else entirely.

I've put the whole program below for anyone who would like to look and see. Please keep in mind till a week ago i had no idea lua or computercraft existed. The blue text is my notes to myself while trying to learn this stuff. I've also never got this program to run past the error reprorted above so bugs, random capital letters, and other assorted screwups are still to be found therein.

P.S. If you know how to keep the formatting for text pasted into a post you could tack that on to your answer as well.. :huh:
Spoiler

Edited by Lyqyd, 20 December 2012 - 07:02 PM.
added code tags


#2 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 20 December 2012 - 06:48 PM

firstly please use code tags around code:
[ code]
[/ code]
without the spaces of course

secondly Lua, like most languages is case sensitive. so when you are calling turtle.getitemCount you should actually be calling turtle.getItemCount notice the capital I :)

EDIT: Everything that dan200 and the other devs created uses camel case, so the first word is lower case, the rest of the words have the front letter capital.

#3 NabsterHax

  • New Members
  • 4 posts

Posted 20 December 2012 - 07:43 PM

Edit: whoops, I'm too tired for this.

#4 BaneIronhand

  • New Members
  • 2 posts
  • LocationSaskatchewan

Posted 20 December 2012 - 08:51 PM

Thanks guys. and yea too tired is right. Stared at that line for over an hour. Must have compared it to the turtle(api) chart a least 10 times and made sure i capitalized the C. :rolleyes:

Thanks for the explanation on posting code I spent some time looking around the forum help section never found that bit anywhere. But then we've established how observant i am already. I'll have to look it over again later.

Note to self...No more posting after bedtime.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users