Jump to content




[Solved] Compare two Tables


3 replies to this topic

#1 CCTech

  • Members
  • 40 posts
  • LocationGermany

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 by OneTech, 05 March 2019 - 08:22 AM.


#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

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.

#3 CCTech

  • Members
  • 40 posts
  • LocationGermany

Posted 03 March 2019 - 11:08 PM

View PostKingofGamesYami, on 03 March 2019 - 11:03 PM, said:

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

#4 CCTech

  • Members
  • 40 posts
  • LocationGermany

Posted 04 March 2019 - 11:46 AM

Well... nevermind. I rewrote the Code.. now it works... why ever..





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users