Jump to content




Blood Magic


  • You cannot reply to this topic
8 replies to this topic

#1 theenlightened

  • Members
  • 3 posts

Posted 08 April 2015 - 07: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...

#2 Dahknee

  • Members
  • 1,808 posts
  • Location/home/da

Posted 08 April 2015 - 01: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

#3 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

Posted 08 April 2015 - 03:45 PM

View PostDannySMc, on 08 April 2015 - 01:59 PM, said:

-- 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()


#4 Dahknee

  • Members
  • 1,808 posts
  • Location/home/da

Posted 08 April 2015 - 04:09 PM

View PostHPWebcamAble, on 08 April 2015 - 03:45 PM, said:

View PostDannySMc, on 08 April 2015 - 01:59 PM, said:

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

#5 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 08 April 2015 - 04: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.

#6 theenlightened

  • Members
  • 3 posts

Posted 08 April 2015 - 09: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 by theenlightened, 09 April 2015 - 12:02 AM.


#7 KingofGamesYami

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

Posted 09 April 2015 - 01: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 [ code ][ /code ]
print( "I'm in code tags" )


#8 theenlightened

  • Members
  • 3 posts

Posted 09 April 2015 - 02: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..

#9 martmists

  • Members
  • 16 posts

Posted 15 May 2015 - 08: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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users