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

OpenPeripherals problem: can't setZIndex

Started by Writer, 15 August 2014 - 09:58 PM
Writer #1
Posted 15 August 2014 - 11:58 PM
Today, I installed OpenPeripherals and some more mods, including Thermal Expansion. I was making a code that showed the energy in the current energy cell. One part of the program is almost the same as the code shown on Direwolf20 ForgeCraft2 S2E25, except only for the peripheral names. There will be another part of the code which will "beautifly" it and so some other things. But when I runned the program, It was calling an error in the line that contained the setZIndex method. I made what I could do to solve this problem. If I took away this method, it would run ok, but I prefer to stick with this method.
The cell is in the back side of the computer and the bridge is in the right side. The code is here:


local energy = peripheral.wrap("back")
local bg = peripheral.wrap("right")

bg.clear()

local energyB = bg.addBox(20, 40, 30, 200, 0x000000, 0.9)
energyB.setZIndex(0)

local overlay = bg.addBox(20, y, 30, energyToBar, 0xFF0000, 1)
overlay.setZIndex(1)

local text = bg.addText(25, 250, energyToText, 0xFFFFFF)

while true do
  local sEnergy = energy.getEnergyStored("back")
  local mEnergy = energy.getMaxEnergyStored("back")
  local percentage = sEnergy / mEnergy
  local ratio = percentage * 100
  text.setText(tostring(math.floor(percentage * 100)).."%")
  overlay.setHeight(ratio * 2)
  overlay.setY((200 + 40) - energyToBar)
end
theoriginalbit #2
Posted 16 August 2014 - 01:34 AM
Please post your error message that you're getting as this is very useful in us assisting you.

I'm going to go ahead and assume its an attempt to call nil error and this could be due to the OpenPeripheral version you're using, I believe that the latest versions are setZ instead of setZIndex.
Lyqyd #3
Posted 16 August 2014 - 01:41 AM
You forgot to approve the question post. :P/>
Writer #4
Posted 16 August 2014 - 01:33 PM
I'm getting the error "attempt to call nil". I'm gonna try the setZ.
Writer #5
Posted 16 August 2014 - 03:01 PM
Made it. Solve it. Thank you. :)/>