Help using turtle.getItemDetail() #1565
-
So im trying to get the turtle to identify any wheat_seed in the inventory and place it into slot 1 before dumping the rest of the inventory. What i was thinking was to use the output of turtle.getItemDetail() to identify the seeds but im not sure how to utilize the outputs yet as im still learning lua and am unsure how to recall output data to be used in a comparison |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
My best advice would be to play around in the Lua REPL1 prompt and get it to pretty print the result of get item detail. I'm expecting you to do this in the Lua prompt so we are not using local, the interactive prompt doesn't handle local the same way that programs do2. pretty = require("cc.pretty")
item = turtle.getItemDetail()
pretty.pretty_print(item) From there you'll see a table printed out, the value that you are interested in is stored in the name key. To access that in your program you'll probably do something like this. local item = turtle.getItemDetail()
if item and item.name == "minecraft:wheat_seeds" then -- Note that I might have the internal name for the seeds wrong, I'm doing that from memory
-- whatever you wanted to do with the seeds
end
Footnotes
|
Beta Was this translation helpful? Give feedback.
My best advice would be to play around in the Lua REPL1 prompt and get it to pretty print the result of get item detail.
I'm expecting you to do this in the Lua prompt so we are not using local, the interactive prompt doesn't handle local the same way that programs do2.
From there you'll see a table printed out, the value that you are interested in is stored in the name key. To access that in your program you'll probably do something like this.