This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Purple's profile picture

Odd turtle.craft issue.

Started by Purple, 02 March 2019 - 05:20 PM
Purple #1
Posted 02 March 2019 - 06:20 PM
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.
Lupus590 #2
Posted 02 March 2019 - 09:37 PM
Have you tied attaching the crafting table on the other side of the turtle?
Purple #3
Posted 02 March 2019 - 11:27 PM
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 on 02 March 2019 - 10:27 PM
KingofGamesYami #4
Posted 02 March 2019 - 11:46 PM
Sometimes line numbers are innaccurate. Can you verify that it is that line by adding some print statements?
Purple #5
Posted 03 March 2019 - 12:03 AM
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 on 02 March 2019 - 11:13 PM
Bomb Bloke #6
Posted 03 March 2019 - 09:14 AM
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.

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…?
Purple #7
Posted 03 March 2019 - 12:55 PM
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()

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 on 03 March 2019 - 12:05 PM
Lupus590 #8
Posted 03 March 2019 - 02:49 PM
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.
Purple #9
Posted 03 March 2019 - 03:07 PM
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 on 03 March 2019 - 02:07 PM
Lupus590 #10
Posted 03 March 2019 - 08:02 PM
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.computercraft.info/wiki/Lua_Resource_Pack_Making_(Tutorial)#Special_Folders
Edited on 03 March 2019 - 07:02 PM
Purple #11
Posted 03 March 2019 - 09:24 PM
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 on 03 March 2019 - 08:50 PM
Lupus590 #12
Posted 04 March 2019 - 12:03 AM
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.
Purple #13
Posted 04 March 2019 - 03:39 PM
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.
KingofGamesYami #14
Posted 04 March 2019 - 03:45 PM
Create a startup file
Lupus590 #15
Posted 04 March 2019 - 06:42 PM
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 on 04 March 2019 - 05:43 PM
Purple #16
Posted 04 March 2019 - 09:11 PM
Thanks you guys. Now I can finish my integrated smelting plant.
Purple #17
Posted 09 March 2019 - 08:57 PM
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 on 09 March 2019 - 09:39 PM
Dog #18
Posted 09 March 2019 - 11:14 PM
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)
Bomb Bloke #19
Posted 09 March 2019 - 11:34 PM
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.
Purple #20
Posted 11 March 2019 - 07:54 PM
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
Lupus590 #21
Posted 11 March 2019 - 09:39 PM
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

go to the end and mass farm endermen?
Purple #22
Posted 12 March 2019 - 05:02 PM
moved to a better place
Edited on 12 March 2019 - 04:02 PM