Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
IceG4merBR

attemp to index a nil value (local 'i')

Question

Got this error, but i have no idea how to fix it, need some help!.

image.png.60d39dc095d3173c407069e70661963d.png

Here is the code.

local component = require("component")
local term = require("term")
local gpu = component.gpu
local cube = component.basic_energy_cube
local event = require("event")
 
local colors = { black = 0x000000, red = 0xC14141}
 
gpu.setBackground(colors.black)
term.clear()
 
local infos = {}
 
cube["stats"] = {}
 
function setInfos()
  infos["stored"] = { x = 3, y = 2, weight = 73, height = 1, title = "STORED ENERGY : ", unit = " RF"}
  infos["capacity"] = { x = 3, y = 4, weight = 73, height = 1, title = "BATTERY CAPACITY : ", unit = " RF"}
end
 
function printInfos(infoName)
  local maxLenght = 15
  local i = infos[infoName]
  gpu.set(i.x, i.y, i.title .. cube.stats[infoName] .. i.unit)
end
 
function updateCubeStats()
  cube.stats["stored"] = cube.getEnergyStored
end
 
function startup()
  updateCubeStats()
  setInfos()
  printInfos()
end
 
startup()
 
repeat
  updateCubeStats()
until event.pull(0.1) == "interrupted"

 

Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0

I got this error now.

image.png.e303047f1b6b4f5a0f48a63e1cc413ac.png

Only changed the printInfos() in startup() to printInfos("stored")

local component = require("component")
local term = require("term")
local gpu = component.gpu
local cube = component.basic_energy_cube
local event = require("event")
 
local colors = { black = 0x000000, red = 0xC14141}
 
gpu.setBackground(colors.black)
term.clear()
 
local infos = {}
 
cube["stats"] = {}
 
function setInfos()
  infos["stored"] = { x = 3, y = 2, weight = 73, height = 1, title = "STORED ENERGY : ", unit = " RF"}
  infos["capacity"] = { x = 3, y = 4, weight = 73, height = 1, title = "BATTERY CAPACITY : ", unit = " RF"}
end
 
function printInfos(infoName)
  local maxLenght = 15
  local i = infos[infoName]
  gpu.set(i.x, i.y, i.title .. cube.stats[infoName] .. i.unit)
end
 
function updateCubeStats()
  cube.stats["stored"] = cube.getEnergyStored
end
 
function startup()
  updateCubeStats()
  setInfos()
  printInfos("stored")
end
 
startup()
 
repeat
  updateCubeStats()
until event.pull(0.1) == "interrupted"
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.