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

Pulling values from OCS

Started by jewelshisen, 02 May 2014 - 02:30 AM
jewelshisen #1
Posted 02 May 2014 - 04:30 AM
Ok so I am trying to get details from a Railcraft Tank and so far I am getting nowhere. All I am wanting to get is the Amount in the tank, what is in it, and the max capacity of the tank.

All of these are things that OCS can get. However I can't, for the life of me, figure out how on earth to get them out of the Matryoshka Doll output that it returns with getTargets or getTargetDetails!

Help me!

EDIT: So I think I may have found out how to navigate that nightmare… They key order is [location]["Tanks"][1]["Amount" / "Capacity"]

Am I the only one wondering if all that nesting is REALLY needed????
Edited on 02 May 2014 - 02:39 AM
Lyqyd #2
Posted 02 May 2014 - 06:01 AM
If the return value of the getTargetDetails call is stored in the variable details,


details.Tanks[1].Amount
details.Tanks[1].Capacity

This is because all tank information is stored in the Tanks table, and there can be multiple tanks per tile entity. All of the nesting is truly necessary.

When in doubt, you can always use ocs/programs/sensorview to view the table structure of the getTargetDetails return value, which usually makes it fairly easy to find what you're looking for.
jewelshisen #3
Posted 02 May 2014 - 04:49 PM
If the return value of the getTargetDetails call is stored in the variable details,


details.Tanks[1].Amount
details.Tanks[1].Capacity

This is because all tank information is stored in the Tanks table, and there can be multiple tanks per tile entity. All of the nesting is truly necessary.

When in doubt, you can always use ocs/programs/sensorview to view the table structure of the getTargetDetails return value, which usually makes it fairly easy to find what you're looking for.

Except for finding out about that [1] needed as that is never shown.
Lyqyd #4
Posted 02 May 2014 - 05:46 PM
I'm fairly certain that it would be shown, the details view only displays what is in the returned table, it doesn't remove anything from it. I can see about grabbing a screenshot this evening to point it out if you like. If it isn't shown, I'll make sure to correct the issue for the next build.
jewelshisen #5
Posted 02 May 2014 - 11:21 PM
I'm fairly certain that it would be shown, the details view only displays what is in the returned table, it doesn't remove anything from it. I can see about grabbing a screenshot this evening to point it out if you like. If it isn't shown, I'll make sure to correct the issue for the next build.

Here is my test system. Just out of sight is a 3x3x4 Steel Tank from Railcraft. https://www.dropbox.com/s/l0xwdhkxatfxwve/Screenshot%202014-05-02%2017.19.52.png
Edited on 02 May 2014 - 09:22 PM
Lyqyd #6
Posted 03 May 2014 - 01:08 AM
That's not ocs/programs/sensorview, which is what I was talking about. However, that does still show the 1, but it is implicit. Notice that the Tanks section looks like this:


Tanks = {
  {
    Amount = 2
  }
}

The tanks table contains a table containing the amount key. Since no key is specified for the table inside the Tanks table, it is assigned the next available numeric index, in this case 1. It could also be written:


Tanks = {
  [1] = {
    Amount = 2
  }
}

Remember, sensorview will explicitly point out that key, whereas the serialization the Lua prompt uses will leave it implicit.