Sunday, 12 April 2015

ComputerCraft - lua tables

So recently I started looking into ComputerCraft (a Minecraft mod) and thus had to start learning lua code.

The first problem I came across was with tables, more specifically inserting extra values into them.
 eg
local caches = {}

caches.insert(caches,v)

where v was a value from a loop I had the program iterating through

however I kept getting the error  "attempt to call nil"

so.. what was I doing wrong?

The example was basing the code off was

local Table = {"One"}
table.insert(Table, "Three")

things learned were

1> Instantiated variables do not take on the properties of their type (un-like some other languages)
2> lua is fully case sensitive throughout

so the solution to all the problems was ... that 'table' was a base function, not an instantiated variable having a function of insert()

so changing ' caches.insert(caches,v) ' to 'table.insert(caches,v)' fixed the problem