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

[Solved] Compare two Tables

Started by CCTech, 03 March 2019 - 05:54 PM
CCTech #1
Posted 03 March 2019 - 06:54 PM
Hello, dear Community,

I am working on a project and I need to compare two tables. The error I get is: attempt to call table
On line 44 and here is my code:


function printComponents()
  local components = {}
  local curComponent = {}
  local dir = Config.CurrentProject
  local CurrentDir = dir
  term.setCursorPos(1,2)
  term.setTextColor(colors.black)
  term.setBackgroundColor(colors.lightGray)
  for _, file in ipairs(fs.list(dir)) do
	components[file] = {
	  name = file,
	  position = term.getCursorPos()
	}
	print("X "..file)
  end
  for _, fname in ipairs(components()) do
	for _, fl in ipairs(fs.list(dir)) do
	  if file == fl then
		print("Test")
	  end
	end
  end
end

The components Table is working as it should.

I tried

print(components["Test"].name)

and Test is the name of a file in the directory the code is looking at. Also I loaded the Config API. That is just not the full code because just that part has to do with the table.

Any help would be appreciated :)/> Have a nice day!
Edited on 05 March 2019 - 07:22 AM
KingofGamesYami #2
Posted 03 March 2019 - 11:03 PM
The error message clearly states your problem:

You have treated components as a function and placed parentheses after it as if to call it. Unfortunately it is not a function and so the error.
CCTech #3
Posted 03 March 2019 - 11:08 PM
The error message clearly states your problem:

You have treated components as a function and placed parentheses after it as if to call it. Unfortunately it is not a function and so the error.

I did? Oh wait.. that was just a typo.. sorry! :P/>
CCTech #4
Posted 04 March 2019 - 11:46 AM
Well… nevermind. I rewrote the Code.. now it works… why ever..