Jump to content




Odd turtle.craft issue.


21 replies to this topic

#1 Purple

  • Members
  • 115 posts
  • LocationAlone in the dark, looking at the pretty lights with dreams of things I can not have.

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.

#2 Lupus590

  • Members
  • 2,029 posts
  • LocationUK

Posted 02 March 2019 - 09:37 PM

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

#3 Purple

  • Members
  • 115 posts
  • LocationAlone in the dark, looking at the pretty lights with dreams of things I can not have.

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 by Purple, 02 March 2019 - 11:27 PM.


#4 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

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?

#5 Purple

  • Members
  • 115 posts
  • LocationAlone in the dark, looking at the pretty lights with dreams of things I can not have.

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 by Purple, 03 March 2019 - 12:13 AM.


#6 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 03 March 2019 - 09:14 AM

 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...?

#7 Purple

  • Members
  • 115 posts
  • LocationAlone in the dark, looking at the pretty lights with dreams of things I can not have.

Posted 03 March 2019 - 12:55 PM

 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.


#8 Lupus590

  • Members
  • 2,029 posts
  • LocationUK

Posted 03 March 2019 - 02:49 PM

 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.

#9 Purple

  • Members
  • 115 posts
  • LocationAlone in the dark, looking at the pretty lights with dreams of things I can not have.

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 by Purple, 03 March 2019 - 03:07 PM.


#10 Lupus590

  • Members
  • 2,029 posts
  • LocationUK

Posted 03 March 2019 - 08:02 PM

 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.


#11 Purple

  • Members
  • 115 posts
  • LocationAlone in the dark, looking at the pretty lights with dreams of things I can not have.

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 by Purple, 03 March 2019 - 09:50 PM.


#12 Lupus590

  • Members
  • 2,029 posts
  • LocationUK

Posted 04 March 2019 - 12:03 AM

 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.

#13 Purple

  • Members
  • 115 posts
  • LocationAlone in the dark, looking at the pretty lights with dreams of things I can not have.

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.

#14 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 04 March 2019 - 03:45 PM

Create a startup file

#15 Lupus590

  • Members
  • 2,029 posts
  • LocationUK

Posted 04 March 2019 - 06:42 PM

 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.


#16 Purple

  • Members
  • 115 posts
  • LocationAlone in the dark, looking at the pretty lights with dreams of things I can not have.

Posted 04 March 2019 - 09:11 PM

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

#17 Purple

  • Members
  • 115 posts
  • LocationAlone in the dark, looking at the pretty lights with dreams of things I can not have.

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 by Purple, 09 March 2019 - 10:39 PM.


#18 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 09 March 2019 - 11:14 PM

 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)

#19 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

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.

#20 Purple

  • Members
  • 115 posts
  • LocationAlone in the dark, looking at the pretty lights with dreams of things I can not have.

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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users