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

getting item's name - can you help for my borken program

Started by bbss, 28 September 2016 - 10:17 PM
bbss #1
Posted 29 September 2016 - 12:17 AM
i want to write a program for automated draconic heart. i want to send required items from turtle to the chest. program have to do send specific number of these items.

here is the code.


local d = {}
local q = {}
local i = 1
local glow = 0
local quartz = 0
local dia = 0
local drac = 0
local res = 0

turtle.select(1)

while i < 6 do
	
turtle.select(i)
	
d[i] = turtle.getItemDetail(i)
	
q[i] = turtle.getItemCount(i)
	
print("",d[i].name)
	
print("",q[i])
	
i = i + 1
end

function find()
		
if d[i].name == minecraft.glowstone then
		  
   i = glow
		
elseif
		  
   d[i].name == minecraft.quartz_block then
		  
   i = quartz
		
elseif
		  
   d[i].name == minecraft.diamond_block then
		  
   i = dia
		
elseif
		  
   d[i].name == DraconicEvolution.draconium then
		  
   i = 1
		  
while i < 6 and d[i].name == DraconicEvolution.draconium do
				
	  if q[i] < q[i+1] then
					
		 i = res
				
	  else
					
		 i = drac
				
	  end  
		  
end
		
end
find()
print(""..glow)
print(""..quartz)
print(""..dia)
print(""..res)
print(""..drac)
		  

i tried to get items' details and i send to their name's to the variable "d". then compared their name's with all 5 items in "find" function. program giving me items' name and quantity. but it give me error in find() function. i don't know lua very much. i think it is about char - string thing. i could not figure out. i hope you guys give me some help. :)/>
Edited on 28 September 2016 - 11:12 PM
Bomb Bloke #2
Posted 29 September 2016 - 12:31 AM
but it give me error in find() function.

And the error says….?
KingofGamesYami #3
Posted 29 September 2016 - 01:17 AM
I would assume "attempt to index ? (a nil value)".

He should be using the string version of "minecraft:glowstone", not minecraft.glowstone. The same applies to all other names in the code.
bbss #4
Posted 29 September 2016 - 01:46 AM
I would assume "attempt to index ? (a nil value)".

He should be using the string version of "minecraft:glowstone", not minecraft.glowstone. The same applies to all other names in the code.

yes it was the error.

when i used

if d[i].name == minecraft:glowstone then
   i = glow
elseif
...
  
end
it said "…then required"

i think i tried with quotes but i gave me error again. i am not sure so i will try will quotes again like "minecraft:glowstone"
bbss #5
Posted 29 September 2016 - 06:58 PM
i tried with quotes like "minecraft:glowstone" but it gave me same error for same line. which is right under function find() line. i can print item's name with "d.name" but i can not compare item's name with it.

edit:

this time it worked. :)/> yes you were right "minecraft:glowstone" sitatution. the problem was about one variable which i can not remember which it is right now. :)/>

i put code here. but it has not finished yet. maybe someone use it or develope more. it has not finished yet.

local d = {}
local q = {}
local i = 1
local glow = 0
local qua = 0
local dia = 0
local drac = 0
local res = 0
local t = 1
local wait = --(how  many seconds need to build ritual, spawn dragon and kill dragon. total time of them.)
local rs = --(which direction you pull redstone signal for activating ritual via fake player)
local act = --(activitaion signal for ritual. you can use level emiter+crafting card for it)
--turtle drops items to up. so you have to need chest there. then you can send the items builder.

os.pullEvent(redstone.getInput(act))

rs.setOutput(rs)
sleep(wait)

while true do --program checks every time quantities of item. so when there is no item in its slot program will be end.
turtle.select(1)
while i < 6 do
	  turtle.select(i)
	  d[i] = turtle.getItemDetail(i)
	  q[i] = turtle.getItemCount(i)
	  i = i + 1
end
function find()
  if  d[i].name == "minecraft:glowstone" then
	  glow = i	  
  elseif
	  d[i].name == "minecraft:quartz_block" then
	  qua = i
  elseif
	  d[i].name == "minecraft:diamond_block" then
	  dia = i
  elseif
	  d[i].name == "DraconicEvolution:draconium" then
	  if d[i].damage == 1 then
		 res = i
	  else
		 drac = i
	  end	  
  end
end
function correctItemCount()
  if q[glow] < 4 then
	 print("Not Enough Glowstone")
	 error()
  end
  if q[drac] < 4 then
	 print("Not Enough Charged Draconium Block")
	 error()
  end
  if not q[res] == 0 then
	 print("Not Enough Resurrection Block")
	 error()
  end
  if q[dia] < 4 then
	 print("Not Enough Diamond Block")
	 error()
  end
  if q[qua] < 12 then
	 print("Not Enough Pillar Quartz Block")
	 error()
  end
end
i = 1
while i < 6 do
	  turtle.select(i)
	  find()
	  i = i+1
end
t = 1
while t < 6 do
	  correctItemCount()
	  turtle.select(t+1)
	  print("Checking Items Counts...")
	  t = t+1
end
print("Glowstone Slot: "..glow)
print("Quantity: "..q[glow])
print("Diamond Block Slot: "..dia)
print("Quantity: "..q[dia])
print("Resurrection Stone Slot: "..res)
print("Quantity: "..q[res])
print("Pillar Quartz Block Slot: "..qua)
print("Quantity: "..q[qua])
print("Charged Draconium Block Slot: "..drac)
print("Quantity: "..q[drac])

turtle.select(glow)
turtle.dropUp(4)
turtle.select(res)
turtle.dropUp(1)
turtle.select(drac)
turtle.dropUp(4)
turtle.select(qua)
turtle.dropUp(12)
turtle.select(dia)
turtle.dropUp(4)
sleep(bekle)
end
Edited on 30 September 2016 - 09:30 AM