←  Ask a Pro

ComputerCraft | Programmable Computers for Minecraft

»

Odd turtle.craft issue.

Purple's Photo Purple 02 Mar 2019

I am getting an odd error with this function:
local function Mix()
  print("Crafting ore dust from item dust " .. detail.name)

  turtle.transferTo(4) -- Put the item away for overflow storage
  turtle.select(4)
  count = turtle.getItemCount(4)

  if(count < 9) then
  else
    i = math.floor( count / 9 )

    print("Now transfering " .. i .. " items")
    print("Aranging...")
    turtle.transferTo( 2, i)
    turtle.transferTo( 3, i)

    turtle.transferTo( 6, i)
    turtle.transferTo( 7, i)
    turtle.transferTo( 8, i)

    turtle.transferTo(10, i)
    turtle.transferTo(11, i)
    turtle.transferTo(12, i)

    print("Crafting...")
    turtle.select(1)
    turtle.craft()
  end
end

Instead of crafting the item the program throws "Attempting to call nill" on the line where turtle.craft() is called. Any ideas? And yes, it is a crafty turtle.
Quote

Lupus590's Photo Lupus590 02 Mar 2019

Have you tied attaching the crafting table on the other side of the turtle?
Quote

Purple's Photo Purple 02 Mar 2019

This is 1.7, You just craft a turtle with a crafting table to get a crafty turtle. No attaching of anything that I know of.
Edited by Purple, 02 March 2019 - 11:27 PM.
Quote

KingofGamesYami's Photo KingofGamesYami 02 Mar 2019

Sometimes line numbers are innaccurate. Can you verify that it is that line by adding some print statements?
Quote

Purple's Photo Purple 03 Mar 2019

That's what the "Crafting" line is for. The program prints "crafting" and than crashes.

Edit: Apparently I've copied the code wrongly to this forum. The line is actually under the select and not above it. It's literally just above the turtle.craft call
Edited by Purple, 03 March 2019 - 12:13 AM.
Quote

Bomb Bloke's Photo Bomb Bloke 03 Mar 2019

 Purple, on 02 March 2019 - 11:27 PM, said:

This is 1.7, You just craft a turtle with a crafting table to get a crafty turtle. No attaching of anything that I know of.

That's one way of attaching things, but you can also do it using the turtle.equipLeft() and turtle.equipRight() calls. This allows you to choose exactly where the accessory will be placed.

 Purple, on 03 March 2019 - 12:03 AM, said:

Apparently I've copied the code wrongly to this forum. The line is actually under the select and not above it. It's literally just above the turtle.craft call

So in this bit of code:

    turtle.select(1)
    turtle.craft()

... you're saying the error is occurring below the select call, but above the craft call?

What? :S

If you mean to say you still believe the craft call is throwing the error, simplify matters by rebooting the turtle to its command prompt and test turtle.craft() through the Lua console, see how it behaves there. If it works like that, show your full code.

Also bear in mind that you can't use slot 4 to hold "spare items" while crafting - turtle.craft() requires the turtle to be holding an exact recipe pattern and nothing else. And are you forgetting to put ingredients into slot 1...?
Quote

Purple's Photo Purple 03 Mar 2019

 Bomb Bloke, on 03 March 2019 - 09:14 AM, said:

If you mean to say you still believe the craft call is throwing the error,
That's what I am saying yes. The program prints "crafting" and than throws an error. And the first call after the print is to turtle.craft()

Quote

simplify matters by rebooting the turtle to its command prompt and test turtle.craft() through the Lua console, see how it behaves there. If it works like that, show your full code.
My full code is
while true do
	turtle.select(1)
	Mix()
end

I manually feed the program materials into slot 1 and it should craft a 3x3 combination item from them.

The desired workflow is:
- Transfer all materials to slot 4.
- Divide materials in slot 4 into the right hand side of the 4x4 grid (slots 2,3,4 - 6,7,8 - 10,11,12)
- Craft items and place them in slot 1
- Materials overflow stays in slot 4

Does the side I crafted the turtle to the crafting table have any bearing on the matter? Like maybe I should use the left hand side (1,2,3 - 5,6,7 - 9,10,11) slots instead? I'll go try that.

Edit: That didn't work.

Also I am loading my program via a resource pack (for easy editing on my part) and for some reason every time the world loads or my turtle turns on it starts this program automatically. I have NOT coded anything that would make that happen!
Edited by Purple, 03 March 2019 - 01:05 PM.
Quote

Lupus590's Photo Lupus590 03 Mar 2019

 Purple, on 03 March 2019 - 12:55 PM, said:

Also I am loading my program via a resource pack (for easy editing on my part) and for some reason every time the world loads or my turtle turns on it starts this program automatically. I have NOT coded anything that would make that happen!

where in your resource pack have you placed your program? I.E. what is the folder stucture of your recource pack?

Also, about your code in the forum post not being identical to the code on your turtle (or in your recource pack), you can upload code to pastebin using pastebin put <filename> and it will give you a url (or just the upload code?) which you can put in your forum post.
Quote

Purple's Photo Purple 03 Mar 2019

The path is: assets\computercraft\lua\rom\apis\

And the code is basically what you see. I just made a single typo.
while true do
  turtle.select(1)
  Mix()
end

local function Mix()
  print("Crafting ore dust from item dust " .. detail.name)
  turtle.transferTo(4) -- Put the item away for overflow storage
  turtle.select(4)
  count = turtle.getItemCount(4)
  if(count < 9) then
  else
	i = math.floor( count / 9 )
	print("Now transfering " .. i .. " items")
	print("Aranging...")
	turtle.transferTo( 2, i)
	turtle.transferTo( 3, i)
	turtle.transferTo( 6, i)
	turtle.transferTo( 7, i)
	turtle.transferTo( 8, i)
	turtle.transferTo(10, i)
	turtle.transferTo(11, i)
	turtle.transferTo(12, i)
	turtle.select(1)
	print("Crafting...")
	turtle.craft()
  end
end

Edited by Purple, 03 March 2019 - 03:07 PM.
Quote

Lupus590's Photo Lupus590 03 Mar 2019

 Purple, on 03 March 2019 - 03:07 PM, said:

The path is: assets\computercraft\lua\rom\apis\

Anything in the apis folder gets ran on startup, you likely want to put it in programs. see this tutorial for more info: http://www.computerc...Special_Folders
Edited by Lupus590, 03 March 2019 - 08:02 PM.
Quote

Purple's Photo Purple 03 Mar 2019

Cool. At least that's one mystery solved. So say I had 3 files in there. How would I chose which one gets run?

Edit: moving it out of the apis folder fixed it. Apparently it was a load order issue of some sort with the actual APIs not being loaded before my code was.
Edited by Purple, 03 March 2019 - 09:50 PM.
Quote

Lupus590's Photo Lupus590 04 Mar 2019

 Purple, on 03 March 2019 - 09:24 PM, said:

Cool. At least that's one mystery solved. So say I had 3 files in there. How would I chose which one gets run?

I belive the order would be the order that the files get discovered, which may be decided by your (real computer's) OS and file system, on Windows I think this is the same as the order that they are listed in file explorer.
Quote

Purple's Photo Purple 04 Mar 2019

This said, what do I need to edit so that on this one turtle and it alone the program gets run on startup? I am a bit rusty with CC.
Quote

KingofGamesYami's Photo KingofGamesYami 04 Mar 2019

Create a startup file
Quote

Lupus590's Photo Lupus590 04 Mar 2019

 KingofGamesYami, on 04 March 2019 - 03:45 PM, said:

Create a startup file on the turtle that you want it to auto run on which shell.run()s the program

(Added bit in italics)
Edited by Lupus590, 04 March 2019 - 06:43 PM.
Quote

Purple's Photo Purple 04 Mar 2019

Thanks you guys. Now I can finish my integrated smelting plant.
Quote

Purple's Photo Purple 09 Mar 2019

Random question. How do I wrap a monitor via a modem and run a program on it? Or do I have to plop a second computer next to it?

Also is there a way to make a turtle drop an item down into a chest underneath it?
Edited by Purple, 09 March 2019 - 10:39 PM.
Quote

Dog's Photo Dog 09 Mar 2019

 Purple, on 09 March 2019 - 08:57 PM, said:

Random question. How do I wrap a monitor via a modem and run a program on it? Or do I have to plop a second computer next to it?

Also is there a way to make a turtle drop an item down into a chest underneath it?

When you right click the modem attached to the monitor you should see some text on screen that says something to the effect of "monitor_0 connected" - the name it shows is the name you want to wrap - e.g. local mon = peripheral.wrap("monitor_0")

To place items in a chest below the turtle, select the correct slot on the turtle then use turtle.dropDown(number to drop)
Quote

Bomb Bloke's Photo Bomb Bloke 09 Mar 2019

Note that you need to be using wired modems in order to wrap remote peripherals. If you want to do it wirelessly, you'll need to place another computer next to the screen in order to relay your commands.
Quote

Purple's Photo Purple 11 Mar 2019

Wireless modems are too expensive anyway. Like, who actually has that many ender pearls?

Thanks you guys. My workshop is well under way. Now if only there was a mod to make my turtles look like dwarves. xD
Quote