Jump to content

Computercraft Dynamic Table Building


Tuxmelv

Recommended Posts

I'm looking at tweaking a program http://pastebin.com/1sqCRqjj, for monitoring a large bank of Redstone Energy Cells. Problem is, I have to manually edit the program with 4 lines every additional REC I have. As I'm currently at 70 RECs and growing, I would like to make this part dynamic where I enter the total RECs I have and it appends the name for me, adding the below up to the max number of RECs I have. Thoughts?

{

["id"] = "redstone_energy_cell_(X)";

["name"] = "Cell(X-1)"

},

Link to comment
Share on other sites

I think this is what you're needing :)


local storageUnitCount = 69 -- Total number of RECs minus 1 since the cell id starts with 0.

local storageUnits = {}

for i=0, storageUnitCount do

    storageUnits = {

        ["id"] = "redstone_energy_cell_" .. i,  -- you concatenate with the .. operator

        ["name"] = "Cell" .. i+1

    }

end

That will build the same table structure you've had to manually define before. I'm a bit confused how you're reading the individual RECs though. Sensors? Computers at each REC?

Link to comment
Share on other sites

I have wired modems on each REC, then the program uses the following code (with net defined as a peripheral.wrap on the modem side) via OpenPeripheral as part of the base tekkit pack.

        for i=#storageUnits,1,-1 do

                  storageUnit = storageUnits[i]

                  capacity = capacity + net.callRemote(storageUnit["id"], "getMaxEnergyStored")

                  amount = amount + net.callRemote(storageUnit["id"], "getEnergyStored")     

        end

Link to comment
Share on other sites

I think the problem might be the fact that every value but the name field starts counting at 0. Do you have a redstone_energy_cell_0 or do you have a redstone_energy_cell_70? It's easy to change the code to start counting at 1.


local storageUnitCount = 70 -- change this

local storageUnits = {}

for i=1, storageUnitCount do -- change this

    storageUnits = {

        ["id"] = "redstone_energy_cell_" .. i,

        ["name"] = "Cell" .. i -- change this

    }

end

Link to comment
Share on other sites

It starts at redstone_energy_cell_0. I was testing this out in a temp creative world first. Had 60 RECs, set it to 59 (2 sets of 30 for max Redstone Energy Conduits) and wired both of them up to the computer via modems. Shows 35.4 mil MJ instead of 36 mil MJ. Being 1 short doesn't bother me that much when there are that many.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...