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

Blood Magic

Started by theenlightened, 08 April 2015 - 06:25 AM
theenlightened #1
Posted 08 April 2015 - 08:25 AM
so i've spent the last 3 hours trying to figure out how to simply read the lp of a blood magic altar without using the division sigil but instead computercraft.

I started knowing nothing about comutercraft and…. basically still know nothing

I did figure out that my altar was a peripheral, and how to wrap it, then i figured out the command i wanted to use, which might be the wrong one.. but weather or not its the write one or not I am determined to figure out how the hell to use it

to the command I wanted to use was getTankInfo() - which basically provides a table, with the capacity as line one and another table as line 2. My question is simple… how the hell do i read that second table, because all i get is the first line then a failed to concatenate

I even tried to turn v intro a tostring(v) - that did not do what I was expecting to say the least..


To sum up.
How do I read a table within a table when a commands results as such?
and
How do I simply read the lp of a blood magic altar, then display it on a monitor?

I'm so very confused…
DannySMc #2
Posted 08 April 2015 - 02:59 PM
Ahh multi-dimensional arrays :D/>

A table is like so:


atable = {
    "first value",
    "second value",
    "third value",
    "etc.",
}
You index the above like:
atable[2]
Output: second value

So here is a "table inside a table":

mdarray = {
  {
    "table 1, value 1",
    "table 1, value 2",
    "table 1, value 3",
  },
  {
    "table 2, value 1",
    "table 2, value 2",
    "table 2, value 3",
  }
}
So there is two tables with 3 values in each table, all inside one table called mdarray, okay?
So to index the 1st table and get the second value, we need to first index the table number then the value number for example:
mdarray[1][2]
Output: table 1, value 2

To index the SECOND table and the THIRD value we do:
mdarray[2][3]
Output: table 2, value 3

Do you see?
If you want just the second table from the above array then you need to do:
mdarray[2]
Then you can do:

for _,v in ipairs(mdarray[2]) do
  print(v)
end

If you are not sure of what is in the table then save it to a file to see what is in it using this:

-- Get table and for example we shall call it "atable":

atable = <peripheralname>.getTankInfo()
local temp = fs.open("output", "w")
temp.write(atable.readAll())
temp.close()
Then the file is saved as output :D/> If you need anything else just PM me :P/>
HPWebcamAble #3
Posted 08 April 2015 - 04:45 PM

-- Get table and for example we shall call it "atable":

atable = <peripheralname>.getTankInfo()
local temp = fs.open("output", "w")
temp.write(atable.readAll())
temp.close()

That won't work, you can't do 'readAll()' on a table

You can use 'textutils.serialize()' instead:

local info = peripheral.getTankInfo()

local temp = fs.open("tankInfo","w")
temp.write( textutils.serialize( info ) )
temp.close()
DannySMc #4
Posted 08 April 2015 - 05:09 PM

-- Get table and for example we shall call it "atable":

atable = <peripheralname>.getTankInfo()
local temp = fs.open("output", "w")
temp.write(atable.readAll())
temp.close()

That won't work, you can't do 'readAll()' on a table

You can use 'textutils.serialize()' instead:

local info = peripheral.getTankInfo()

local temp = fs.open("tankInfo","w")
temp.write( textutils.serialize( info ) )
temp.close()

Ahh yes apologies
SquidDev #5
Posted 08 April 2015 - 05:44 PM
From memory you can use .getInfo instead on your peripheral. This should generate:


{
  capacity = 10000, -- Altar capacity
  contents = {
    amount = 1000, -- Current altar ammount
    id = "blood_magic:life_essence_or_something",
  }
}

You can then do:

print("Total = " .. t.capacity)
print("Current = " .. t.contents.amount)

You can have a look at the converters here and here.
theenlightened #6
Posted 08 April 2015 - 10:42 PM
a = peripheral.wrap (tealtar_0) or peripheral.wrap ("direction")
cur
rlp = tostring (math.floor (a.getTankInfo()[1]["amount"]))
print (currlp .. " LP")

Why does this not work…?
Also reading @squiddev's post I do realise that now.. also with this block, getTankInfo() and getInfo() report the same (which is true with all tanks)
Edited on 08 April 2015 - 11:02 PM
KingofGamesYami #7
Posted 09 April 2015 - 02:07 AM
What doesn't work about it? I'd post your exact code, as tealter_0 is a variable and "direction" isn't a valid side (should be "right", "left", "top", "bottom", etc.)

Also what you posted should error on line 2, because you have an undefined variable doing nothing (cur)

PS: code tags

print( "I'm in code tags" )
theenlightened #8
Posted 09 April 2015 - 03:15 AM
I give up….. a simple tasks of display the lp level of an altar on a monitor shouldn't be this hard…. I just don't get it… Thanks for your input… but unless someone wants to just give me the code… imma stick to my divination sigil..
martmists #9
Posted 15 May 2015 - 09:09 PM
i made a program like that :P/>

available on the reddit forums, or pastebin get v9UUAq8q

altar via peripheral proxy, monitor on top of computer