Jump to content




Turtle While loop help


  • You cannot reply to this topic
2 replies to this topic

#1 pitchblac23

  • New Members
  • 2 posts

Posted 01 April 2013 - 05:30 PM

hello all ill make this question short it can get pretty long tho so bare with me here :P

im working on making a basic house building (10x10) program with while loops and if and elseifs so now my question is : on my program i have my functions and ifs and loops so far setup in this manner

function Fuel()
if turtle.getFuelLevel <= 1 then
  turtle.select(1)
  turtle.refuel(1)
 end
end
//other functions
i = 1
while i <= 10 do
if turtle.getItemCount(2) >= 20 then
  i = 1
  while i <= 10 do
	Fuel()
	Line()
	i = i + 1
  elseif turtle.getItemCount(2) <= 20
		  print("Need 20 in slot 2")
  end
end
end

and it seems after it finishes it stops and wont loop it over again please help me im a lua noob as you probably can tell mine is much bigger then this but i dont have access to the file to copy and paste if needed to i can finish the rest of it this is just the gist of it

#2 InDieTasten

  • Members
  • 357 posts
  • LocationGermany

Posted 01 April 2013 - 07:00 PM

let me format that for you:
Spoiler
alright. then theres a weird ending. so I'll fix that, too:


Spoiler
alright. now the problem you described. it appears because you are using a loop in a loop. no problem as far as they don't use the same index. in your case i. so so I'll fix that as well:

Spoiler
so. thats all i can do for now because i don't have enough information to test your program of functionality, so it's you turn. would be easier to help you if you posted the complete program. because i don't remember the function line(). correct me, but this function needs to be somewhere in your code, doesn't it?

#3 pitchblac23

  • New Members
  • 2 posts

Posted 02 April 2013 - 09:08 AM

ya my line function is just this

fucntion Line()
	turtle.select(2)  
	turtle.digDown()
	turtle.placeDown()
end

and i will try out every thing you have showed me there and see it its working

PS. Thank you so much i didnt even think about needing a different index XD shows how bad i am but im learning





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users