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

Assigning values to a table [Resolved]

Started by WillisDoering, 01 July 2017 - 09:01 PM
WillisDoering #1
Posted 01 July 2017 - 11:01 PM
I have been trying to create a table that will later be used to create text boxes. This is in a custom API I am writing to use with various programs. When I try to call the function that creates it, it gives the error "attempt to index ? (a nil value)". Below I have the specific code and any relevant variables.


--values of variables used in function
section = "home"
page = 1

--call used in program using API
gui.set_text("test", "This is a test", 3, 3)

--broken function in API
function set_text(name, data, x, y)
  text[section][page][name]["data"] = data
  text[section][page][name]["x"] = x
  text[section][page][name]["y"] = y
  text[section][page][name]["display"] = true
end
Edited on 01 July 2017 - 09:56 PM
KingofGamesYami #2
Posted 01 July 2017 - 11:08 PM
While text is probably a table, text[something] wont be until you make it one. You'll have to do this for every layer of indexes.
WillisDoering #3
Posted 01 July 2017 - 11:56 PM
Thanks for the advice. That fixed it. I feel like I should have seen this sooner.