Jump to content




Lua Script Help!



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

#1 Mnoone96

  • New Members
  • 1 posts

Posted 13 September 2015 - 03:14 PM

Hi There!

I wrote this script to fill a quarry and im getting pack an error in line 12 when i involve user input. Error: 'then' expected. Need Help!!

  • function placeBlockDownForward()


  • length = 0


  • -- Length limit is 1 less than actual --


  • while length <= 104 do


  • turtle.forward()


  • turtle.placeDown()


  • if turtle.getItemCount() == 0 and select == 16 then


  • print "Not enough Dirt. Please place in more and hit enter 'y'"


  • re = io.read()


  • if re = "y" then


  • select = 0


  • turtle.select(select)


  • end


  • elseif turtle.getItemCount() == 0 then


  • select = select + 1


  • turtle.select(select)


  • end


  • length = length + 1


  • end


  • end


  • function placeBlockDownBack()


  • length = 0


  • -- Length limit is 1 less than actual --


  • while length <= 104 do


  • turtle.back()


  • turtle.placeDown()


  • if turtle.getItemCount() == 0 and select == 16 then


  • print "Not enough Dirt. Please place in more and hit enter 'y'"


  • re = io.read()


  • if re = "y" then


  • select = 0


  • turtle.select(select)


  • end


  • elseif turtle.getItemCount() == 0 then


  • select = select + 1


  • turtle.select(select)


  • end


  • length = length + 1


  • end


  • end


  • function fullCycleReverse()


  • placeBlockDownBack()


  • turtle.up()


  • placeBlockDownForward()


  • turtle.up()


  • end


  • function fullCycle()


  • placeBlockDownForward()


  • turtle.up()


  • turtle.placeDown()


  • placeBlockDownBack()


  • turtle.up()


  • turtle.placeDown()


  • end


  • function placeBlock()


  • length = 0


  • while length <= 103 do


  • turtle.back()


  • turtle.place()


  • if turtle.getItemCount() == 0 then


  • select = select + 1


  • turtle.select(select)


  • end


  • length = length + 1


  • end


  • end


  • function turtleGoDown()


  • depth = 0


  • while depth <= 59 do


  • turtle.down()


  • depth = depth + 1


  • end


  • end


  • select = 1


  • turtle.select(select)


  • turtle.forward()


  • turtleGoDown()


  • turtle.turnRight()


  • turtle.turnRight()


  • placeBlock()


  • turtle.back()


  • turtle.place()


  • turtle.up()


  • turtle.up()


  • function fullCycleTwentySeven()


  • fullCycle()


  • fullCycle()


  • fullCycle()


  • fullCycle()


  • fullCycle()


  • fullCycle()


  • fullCycle()


  • fullCycle()


  • fullCycle()


  • fullCycle()


  • fullCycle()


  • fullCycle()


  • fullCycle()


  • fullCycle()


  • fullCycle()


  • fullCycle()


  • fullCycle()


  • fullCycle()


  • fullCycle()


  • fullCycle()


  • fullCycle()


  • fullCycle()


  • fullCycle()


  • fullCycle()


  • fullCycle()


  • fullCycle()


  • end


  • fullCycleTwentySeven()


#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 13 September 2015 - 05:40 PM

Moved to Ask a Pro.

#3 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 13 September 2015 - 06:06 PM

On lines 10 and 31 you have
if re = "y" then

they should be
if re == "y" then

You need a double = because you are doing a comparison - a single = is used for setting a variable

Here is your code, with corrections, indented, and placed in code tags - I've place it inside a spoiler due to it's length. I also took the liberty of replacing your fullCycleTwentySeven() function with a loop, so it's easier to read and manage in the future.

Your Code

One more thing...I noticed on lines 11 and 32 you are setting select to 0. I may be wrong, but I think turtle slots are numbered 1-16, not 0-15. Trying to select slot 0 *may* cause an error.

Edited by Dog, 13 September 2015 - 06:36 PM.






2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users