2015-02-05 5 views
1

거북이 용 마이닝 프로그램을 ComputerCraft mod에서 만들고 싶습니다. 나는이 만든 :ComputerCraft 거북이 마이닝 프로그램

function initVariables() 
    stone = 0 
    cobblestone = 0 
    coal = 0 
    iron = 0 
    gold = 0 
    redstone = 0 
    diamond = 0 
    lapis = 0 
    dirt = 0 
    gravel = 0 
    sand = 0 
    emerald = 0 
    mossy = 0 
end 

function count() 
    local success, data = turtle.inspect() 

    if success then 
     if data.name == "minecraft:stone" then stone = stone + 1 end 
     if data.name == "minecraft:cobblestone" then cobblestone = cobblestone + 1 end 
     if data.name == "minecraft:coal_ore" then coal = coal + 1 end 
     if data.name == "minecraft:iron_ore" then iron = iron + 1 end 
     if data.name == "minecraft:gold_ore" then gold = gold + 1 end 
     if data.name == "minecraft:redstone_ore" then redstone = redstone + 1 end 
     if data.name == "minecraft:diamond_ore" then diamond = diamond + 1 end 
     if data.name == "minecraft:lapis_ore" then lapis = lapis + 1 end 
     if data.name == "minecraft:dirt" then dirt = dirt + 1 end 
     if data.name == "minecraft:gravel" then gravel = gravel + 1 end 
     if data.name == "minecraft:sand" then sand = sand + 1 end 
     if data.name == "minecraft:emerald_ore" then emerald = emerald + 1 end 
     if data.name == "minecraft:mossy_cobblestone" then mossy = mossy + 1 end 
    end 
end 

function display() 
    print("I have mined:") 
     if stone > 0 then 
      print(stone .. " blocks of stone") 
     end 

     if cobblestone > 0 then 
      print(cobblestone .. " blocks of cobblestone") 
     end 

     if coal > 0 then 
      print(coal .. " coal ores") 
     end 

     if iron > 0 then 
      print(iron .. " iron ores") 
     end 

     if gold > 0 then 
      print(gold .. " gold ores") 
     end 

     if redstone > 0 then 
      print(redstone .. " redstone ores") 
     end 

     if diamond > 0 then 
      print(diamond .. " diamond ores") 
     end 

     if lapis > 0 then 
      print(lapis .. " lapis ores") 
     end 

     if dirt > 0 then 
      print(dirt .. " blocks of dirt") 
     end 

     if gravel > 0 then 
      print(gravel .. " blocks of gravel") 
     end 

     if sand > 0 then 
      print(sand .. " blocks of sand") 
     end 

     if emerald > 0 then 
      print(emerald .. " emerald ores") 
     end 

     if mossy > 0 then 
      print(mossy .. " blocks of mossy cobblestone") 
     end 
end 

function refuel() 
    turtle.select(1) 
    turtle.refuel(1) 
end 

function checkIfBack() 
    fuelCount = turtle.getItemCount(1) 
    if fuelCount < 5 then 
     return true 
    else 
     return false 
    end 
end 

function back() 
    if checkIfBack() == true then 
     turtle.turnLeft() 
     turtle.turnLeft() 

     local stopblock, data = turtle.inspect() 
     if data.name ~= "minecraft:redstone_block" then 
      if turtle.forward() == false then 
       turtle.attack() 
      else 
       turtle.forward() 
      end 
      return false 
     else 
      return true 
     end 
    end 
end 

function move() 
    if back() == false then 
     fuel = turtle.getTurtleLevel() 
     if fuel < 10 then refuel() end 
     if turtle.inspect() == false then 
      turtle.forward() 
     else 
      count() 
      turtle.dig() 
      turtle.attack() 
     end 
    else 
     print("END OF PROGRAM") 
    end 
end 

initVariables() 
while true do move() end 

을하지만 거북이는 내가 무슨 일을하고있는 중이 야, 돌아 서서 앞으로 3 개 블록을 간다, 돌아서, 3 개 블록 앞으로 등

간다 앞으로 3 개 블록을 간다?

답변

1

당신은 back 기능을 호출하고 있습니다.

back 함수가 turtle.forward() 함수를 두 번 호출하고 있습니다. 첫 번째로 false를 확인하고 두 번째로 호출 할 때 (이후에) 호출합니다.

그러면 move 함수가이를 호출합니다.

function back() 
    if checkIfBack() == true then 
     -- turtle.turnLeft() -- this makes it turtle 
     -- turtle.turnLeft() -- also this.. 

     local stopblock, data = turtle.inspect() 
     if data.name ~= "minecraft:redstone_block" then 
      if turtle.forward() == false then 
       turtle.attack() 
      -- else -- if we move forward == false then u want him to move? no need 
       -- turtle.forward() -- 2nd forward move 
      end 
      return false 
     else 
      return true 
     end 
    end 
end 

function move() 
    if back() == false then 
     fuel = turtle.getTurtleLevel() 
     if fuel < 10 then refuel() end 
     if turtle.inspect() == false then 
      -- turtle.forward() -- 3rd call to move forward.. 
     else 
      count() 
      turtle.dig() 
      turtle.attack() 
     end 
    else 
     print("END OF PROGRAM") 
    end 
end 
+0

좋아요를보십시오, 나는 그것을 해결했지만 거북이는 여전히 앞으로가는 등 주위집니다 : – mieciu0077

+0

가이 개 기능 – das

+0

를 교체 \ 나도 몰라 당신이 날 회전을 삭제하려는 이유 , 등()은 연료가 없을 때 그것을 회전시켜 집으로 돌아 가야한다. 그리고 그 후에 "오류가 발생할 때까지"프로그램 끝 "을 여러 번 표시합니다"너무 오래 걸리지 않고 "; – mieciu0077