Blood magic turtle problem

Started by flowfy, Jan 25, 2020, 06:22 AM

Previous topic - Next topic

flowfy

Hi
I'm playing the mod pack ftb infinity evolved skyblock with computercraft version 1.75 and trying to automate my blood altar.

Porely something must be wrong with my code. The turtle always shows this error:

bios:14: [string "startup"]:20 "end" expected (to close "if" at line 4)

If I add an "end" more at the end of the script it changes nothing.

Can someone help me what is wrong with this script?

Here is the script:
Quotealtar = peripheral.wrap("front")
while true do
os.sleep(0.5)
if(turtle.suckUp(1)) then
oldItem = turtle.getItemDetail(1).name
print("Old item: ".. oldItem)
turtle.drop(1)
while true do
os.sleep(0.1)
currentItem=altar.getAllStacks()[1].a
print("Current item: " ..currentItem)
if(oldItem ~= currentItem) then
print("Finished!")
turtle.suck(1)
turtle.turnLeft()
turtle.drop()
turtle.turnRight()
break
end
end


SquidDev

The easiest thing to do in these cases is add an indent after every while and if, and remove it after an "end". This helps you see the layout of the code a little better:

local altar = peripheral.wrap("front")
while true do
  os.sleep(0.5)
  if turtle.suckUp(1) then
    oldItem = turtle.getItemDetail(1).name
    print("Old item: " .. oldItem)
    turtle.drop(1)
    while true do
      os.sleep(0.1)
      currentItem = altar.getAllStacks()[1].a
      print("Current item: " .. currentItem)
      if oldItem ~= currentItem then
        print("Finished!")
        turtle.suck(1)
        turtle.turnLeft()
        turtle.drop()
        turtle.turnRight()
        break
      end
    end


There's two indents left at the bottom there, so we need to add two ends! (which is why adding one wasn't enough).
GitHub | CC:Tweaked: A ComputerCraft fork | Plethora: A peripheral mod

flowfy

Sorry my english isn't the best.
I've tried the code you pasted but it don't work.
If I add two "end"'s more at the end of the code the turtle craps the item in the chest above an put the item in th altar but the turtle dont pickup the item again from the altar.


Lupus590

all squiddev did was reformat your existing code, to fix it you still need to add two ends (like he said)

here's the same code with the ends added
local altar = peripheral.wrap("front")
while true do
  os.sleep(0.5)
  if turtle.suckUp(1) then
    oldItem = turtle.getItemDetail(1).name
    print("Old item: " .. oldItem)
    turtle.drop(1)
    while true do
      os.sleep(0.1)
      currentItem = altar.getAllStacks()[1].a
      print("Current item: " .. currentItem)
      if oldItem ~= currentItem then
        print("Finished!")
        turtle.suck(1)
        turtle.turnLeft()
        turtle.drop()
        turtle.turnRight()
        break
      end
    end
  end
end