Jump to content




Tree farm help While statement


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

#1 Tohrik

  • Members
  • 3 posts

Posted 13 April 2016 - 06:47 AM

Spoiler
So this is my second time using Lua. This is for a 15x5 tree farm.
My problem is that in my while statement it doesn't want to seem to execute turtle.suck and it only goes around one time. What am I doing wrong?

Sorry if my code is a bit messy and thanks in advance.

#2 Lupus590

  • Members
  • 2,028 posts
  • LocationUK

Posted 13 April 2016 - 07:58 AM

turtle.suckUp()

capital u

#3 Tohrik

  • Members
  • 3 posts

Posted 13 April 2016 - 08:29 AM

Changed it, still just pushes it the sapling forward.

#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 13 April 2016 - 09:47 AM

I've got a hunch it's got something to do with your mystery "fuelcheck()" function.

It's not defined in this script, so either you're not showing us the code you've got on your turtle, or you've executed some other script which defined it. Because you're not localising your functions, they stay in memory (in the shell's environment table, used for storing globals) until the turtle shuts down, meaning that this later script can still call them...

http://lua-users.org...i/ScopeTutorial

I'm also not sure when you're wanting the turtle to suck. At the moment you're only ordering it once per complete loop, so certainly most saplings are going to be pushed around.

#5 Tohrik

  • Members
  • 3 posts

Posted 13 April 2016 - 04:51 PM

I'm wanting the saplings to be sucked up continuously,.since there isn't a specific point in time that a sapling would drop. Sorry about the fuelcheck function that's meant to be changed to fuellevel().

#6 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 14 April 2016 - 12:15 AM

In that case, consider tying suction to a function for moving forward:

local function forward(amount)
  for i = 1, amount do
    turtle.suck()
    turtle.suckUp()
    repeat until turtle.forward()  --# turtle.forward() returns false if it fails for some reason, eg a mob in the way
  end
end






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users