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

Get item ID inside blood magic altar.

Started by fanzypantzy, 16 January 2016 - 12:05 AM
fanzypantzy #1
Posted 16 January 2016 - 01:05 AM
Is it possible to easily just get the ID of anything currently inside a blood magic altar?
Edited on 16 January 2016 - 11:09 PM
Bomb Bloke #2
Posted 16 January 2016 - 01:20 AM
Not through vanilla ComputerCraft. OpenPeripheral may allow it. Stick a computer next to an altar, run eg this script on it, see what that tells you.
KingofGamesYami #3
Posted 16 January 2016 - 01:21 AM
I doubt computercraft alone could do this. However, if OpenPeripherals is available, depending on the version of OpenP and Blood Magic, maybe.

This will give you either a list of methods for the alter (if it's a peripheral), or tell you it's not one (if it's not a peripheral).


local side = "top" --#this should be whatever side the alter is on
if peripheral.isPresent( side ) then
  for k, v in pairs( peripheral.getMethods( side ) do
    print( k )
  end
else
  print( "Not a Peripheral!" )
end

EditNinja'd
Edited on 16 January 2016 - 12:21 AM
fanzypantzy #4
Posted 16 January 2016 - 11:43 PM
Alright I thought it first was a little over my head and did it another way. But if I can understand this I can redo some of my script to make the automation much faster :)/>

Here are the method I think I will have the most use of:


My questions are:

How do I get the different parts of getInfo() under the blood altar. It returns more than one thing and I would like to be able to call both the capacity and contents separately.
I'm really really new to this and have never coded anything else than a simple sheep farm. How can I get the capacity and do a simple "while capacity > 8000 do" or something similar. And how can I get the contents so I can wait until the right slate is finished. Again as simple as "contents = Bloodmagic:Blankslate" or something like that.

Here is the script I am working in atm, it does all the filtering manually with BC emzuli pipes and gates.

Spoiler

local details = turtle.getItemDetail()
-- Blank Slate variables
local bSlateitemcompare = turtle.getItemCount(2)
local aStoneitemcompare = turtle.getItemCount(1)
local rSlateitemcompare = turtle.getItemCount(3)
local iSlateitemcompare = turtle.getItemCount(4)
local dSlateitemcompare = turtle.getItemCount(5)
local bSlate = 0
local rSlate = 0
local iSlate = 0
local dSlate = 0
local aStone = 0
local maxStack = 64
local minStack = 1
local SlateProcessing = blSlate
-- variable names
-- blank slate = blSlate
-- runic slate = ruSlate
-- imbued slate = imSlate
-- demonic slate = deSlate

function resetVariables()
bSlateitemcompare = turtle.getItemCount(2)
aStoneitemcompare = turtle.getItemCount(1)
rSlateitemcompare = turtle.getItemCount(3)
iSlateitemcompare = turtle.getItemCount(4)
dSlateitemcompare = turtle.getItemCount(5)

bSlate = bSlateitemcompare
rSlate = rSlateitemcompare
iSlate = iSlateitemcompare
dSlate = dSlateitemcompare

aStone = aStoneitemcompare
print("Number of Arcane Stone in inventory: "..aStone)
print("Number of Blank slate in inventory: "..bSlate)
print("Number of Blank slate in inventory: "..rSlate)
print("Number of Blank slate in inventory: "..iSlate)
print("Number of Blank slate in inventory: "..dSlate)
end
function blankslate()
if aStone > minStack then
  if details.name == "Thaumcraft:blockCosmeticSolid" then
   turtle.select(1)
   turtle.drop(1)
  
   if bSlate < maxStack then
    redstone.setBundledOutput("back", colors.red)
    SlateProcessing = blSlate
    print("Making Blank Slate")
   
    while turtle.getItemCount(2) == bSlate do
	 turtle.suckUp()
	 sleep(0.1)
    end
   else
   
    if rSlate < maxStack then
	 redstone.setBundledOutput("back", colors.green)
	 SlateProcessing = ruSlate
	 print("Making Runic Slate")
	
	 while turtle.getItemCount(3) == rSlate do
	  turtle.suckUp()
	  sleep(0.1)
	 end
    else
	
	 if iSlate < maxStack then
	  redstone.setBundledOutput("back", colors.blue)
	  SlateProcessing = imSlate
	  print("Making Imbued Slate")
	 
	  while turtle.getItemCount(4) == iSlate do
	   turtle.suckUp()
	   sleep(0.1)
	  end
	 else
	
	  if dSlate < maxStack then
	   redstone.setBundledOutput("back", colors.yellow)
	   SlateProcessing = deSlate
	   print("Making Demonic Slate")
	  
	   while turtle.getItemCount(5) == dSlate do
	    turtle.suckUp()
	    sleep(0.1)
	   end
	  else
	   dropSlate()
	  end
	 end
    end  
   end 
  
  else
   print("Block is not Arcane Stone")
   error()
  end

  print("Blank slate pulled")
  redstone.setBundledOutput("back", 0)
else
  print("Not enough Arcane Stone or full of Blank Slate")
  stockArcaneStone()
end


end
function stockArcaneStone()
  if aStone < maxStack then
   turtle.turnRight()
   turtle.select(1)
   sleep(0.2)
   turtle.suck(64 - aStone)
   turtle.turnLeft()
   print("Pulled arcane stone")
  else
   print("There is enough arcane stone")
  end
end
function dropSlate()
turtle.turnRight()
if bSlate > minStack then
  turtle.select(2)
  turtle.drop(bSlate - 1)
  print("Pushed blank slate")
end

if rSlate > minStack then
  turtle.select(3)
  turtle.drop(rSlate - 1)
  print("Pushed runic slate")
end

if iSlate > minStack then
  turtle.select(4)
  turtle.drop(iSlate - 1)
  print("Pushed imbued slate")
end

if dSlate > minStack then
  turtle.select(5)
  turtle.drop(dSlate - 1)
  print("Pushed demonic slate")
end
end

while redstone.getInput("left") do
resetVariables()
blankslate()
sleep(0.1)
end
Edited on 16 January 2016 - 10:45 PM
Ajt86 #5
Posted 16 January 2016 - 11:47 PM
It returns a table, so just get the index in the table.


local atable = {
  ["key"] = "Value"
}
print(atable.key)    -- Prints "Value"
print(atable["key"])    -- Prints "Value"

The latter is more useful when Lua could misinterpret the dot notation (spaces or special characters in key). It is also more useful when you're dynamically indexing the table.
Dragon53535 #6
Posted 16 January 2016 - 11:52 PM
It actually returns a NESTED table, which is a table in a table.


local tbl = drive.getInfo()
tbl.contents.amount
will be the numerical value of it's current amount
fanzypantzy #7
Posted 17 January 2016 - 12:08 AM
Thank you Dragon that solves one part of the question :)/>

Could this give me the information about the block inside the blood altar?


The big question is: teach me like I am 5, what is this proxy table thingy?
Dragon53535 #8
Posted 17 January 2016 - 12:19 AM
What does the rest of the statement regarding it say?
fanzypantzy #9
Posted 17 January 2016 - 12:23 AM
Are you thinking of this?



I mean it's not giving me much to go on to figure out what is in the table or how to get to it:

Dragon53535 #10
Posted 17 January 2016 - 12:28 AM
From what I can see, it's returning something that can't be easily serialized. or it might…

Try running this to see what's in it

textutils.serialize(drive.getAllStacks())
If you get an error, that means that it's probably got a function in it somewhere.
If it does error, we'll work on that next.

I think proxy is negligible right now, since you're referencing the altar you care about anyways, no need for a proxy I assume.
fanzypantzy #11
Posted 17 January 2016 - 12:30 AM
Does this classify as an error in your books? :)/>

Dragon53535 #12
Posted 17 January 2016 - 12:37 AM
Figures… I'm assuming you know how to edit and run files, so make a file and run this:


local side = "left"
local drive = peripheral.wrap(side)
local file = fs.open("tableFile","w")
local function readTable(tbl,previous)
  previous = previous or ""
  for a,v in pairs(tbl) do
	if type(v) == table then
	  readTable(tbl,previous..a..":")
	else
	  file.writeLine(previous..a.." = " .. type(v))
	end
  end
end
readTable(drive.getAllStacks(),"")
file.close()

And then open the tableFile file
Edited on 16 January 2016 - 11:39 PM
fanzypantzy #13
Posted 17 January 2016 - 12:42 AM
Alright the tablefile contains:


1 = table
Dragon53535 #14
Posted 17 January 2016 - 12:45 AM
That's my fault.

local side = "left"
local drive = peripheral.wrap(side)
local file = fs.open("tableFile","w")
local function readTable(tbl,previous)
  previous = previous or ""
  for a,v in pairs(tbl) do
		if type(v) == "table" then --# I forgot the quotes here
		  readTable(tbl,previous..a..":")
		else
		  file.writeLine(previous..a.." = " .. type(v))
		end
  end
end
readTable(drive.getAllStacks(),"")
file.close()
Edited on 16 January 2016 - 11:46 PM
fanzypantzy #15
Posted 17 January 2016 - 12:49 AM
When I ran it this happened. Though I changed the side to front since it is facing forward atm.



But when I put the side back to left it returned 216 which is a blood interface block though. I assume you wanted the side to be the blood altar side.
Dragon53535 #16
Posted 17 January 2016 - 12:51 AM
Another one of my faults


local side = "left"
local drive = peripheral.wrap(side)
local file = fs.open("tableFile","w")
local function readTable(tbl,previous)
  previous = previous or ""
  for a,v in pairs(tbl) do
				if type(v) == "table" then --# I forgot the quotes here
				  readTable(v,previous..a..":") --#I was passing tbl here, which basically did this over and over again, without changing it's result
				else
				  file.writeLine(previous..a.." = " .. type(v))
				end
  end
end
readTable(drive.getAllStacks(),"")
file.close()

Yay for typos and mistakes…
Edited on 16 January 2016 - 11:52 PM
fanzypantzy #17
Posted 17 January 2016 - 12:52 AM
Hehe np. Here is the tablefile:


1:listSources = function
1:getAdvancedMethodsData = function
1:all = function
1:listMethods = function
1:doc = function
1:keys = function
1:basic = function
1:select = function
1:single = function
Dragon53535 #18
Posted 17 January 2016 - 12:54 AM
This looks like it's returning a table that has a peripheral in it. Given this thought, I'd go with:


drive.getAllStacks()[1].listMethods()
I probably should say, I mean plug that back into the lua prompt after wrapping the altar again.
Edited on 16 January 2016 - 11:57 PM
fanzypantzy #19
Posted 17 January 2016 - 12:59 AM
Here we go, everything you are doing is slightly over my head, but I trust you :)/>:

Dragon53535 #20
Posted 17 January 2016 - 01:03 AM
I'll just go with probably not this function then.
Just to test though, what do these get you?

drive.getAllStacks()[1].keys()
drive.getAllStacks()[1].listSources()


I'd also check what other methods you can use for the altar.

drive.listMethods()
fanzypantzy #21
Posted 17 January 2016 - 01:12 AM
Those give me







This one could probably say something, but how do I write it to a file like you did just now. It returns so much at once.



Bump: found this under getStaclnSlot(1)

I got a blood orb in the altar so this seem to work.

Dragon53535 #22
Posted 17 January 2016 - 01:16 AM
Writing files using code: Tutorial

As for what I'm thinking here, lets check out
drive.getStackInSlot(1) --# IT actually occurs to me, this probably gives us the exact table that allStacks does, but only the [1] table.
and
drive.getAllStacks()[1].listMethods("properties")
And maybe
drive.getInventoryName()
Edited on 17 January 2016 - 12:17 AM
fanzypantzy #23
Posted 17 January 2016 - 01:22 AM
Running the drive.getStackInSlot(1) and then printing the ID part of the table seem to give me the correct ID of what is in the slot. But running this and taking something out gives me 216.


while true do

tbl = drive.getStackInSlot(1)
message = tbl.id
print(message)
sleep(0.2)
end






From here on out I'm pretty sure i now know what I need to finish this :)/> and make it faster, and need no clunky BC pipes and redpower wiring. I kinda led you on a wild goose chase there, but I learned a thing or two about how tables work. ^^ Though why does it return 216 and stops the program when nothing is in the altar?
Edited on 17 January 2016 - 12:24 AM
Dragon53535 #24
Posted 17 January 2016 - 01:26 AM
216 sounds like it's just either nothing, or the altar's numerical id. With that information though, that means that you can easily know what's inside.

local item = drive.getStackInSlot(1)
if type(item) ~= "table" then --#HA! I remembered the " 's
  print(item.id)
  print(item.qty) --#The amount inside.
end
Edited on 17 January 2016 - 12:27 AM
fanzypantzy #25
Posted 17 January 2016 - 01:33 AM
I guess I'll just have to make sure I never use getStackInSlot while nothing is inside the altar. Or else the program stops. But I have no need to do so either, so np for me. Thank you very much dragon. Now onto the rewriting.
Pyuu #26
Posted 17 January 2016 - 01:34 AM
You could use a pcall to prevent erroring from happening.
Here is an example:

st,er = pcall(turtle.getStackInSlot,value)
if er then
-- Yay, no broken program.
else
val = turtle.getStackInSlot(value)
end
Dragon53535 #27
Posted 17 January 2016 - 01:37 AM
You could use a pcall to prevent erroring from happening.
Here is an example:

st,er = pcall(turtle.getStackInSlot,value)
if er then
-- Yay, no broken program.
else
val = turtle.getStackInSlot(value)
end
First, good catch, second, your code can be shortened to this:

local noError,returnVal = pcall(drive.getStackInSlot,1)
if noError then
  --#There was no error, returnVal is now your table, in which it's good.
end
fanzypantzy #28
Posted 17 January 2016 - 01:46 AM
Tiny question: If I wrap a peripheral and then turn a turtle, then turn it back to the original position. Do I then need to rewrap the peripherals?
Pyuu #29
Posted 17 January 2016 - 01:48 AM
No you don't have to rewrap the peripherals.