Jump to content




[Lua][Error] printing a table element


  • You cannot reply to this topic
2 replies to this topic

#1 Coal64

  • New Members
  • 2 posts

Posted 21 February 2013 - 07:45 PM

title: [Lua][Error] printing a table element

I keep geting a error, "program:2: attempt to call table" I am just starting lua, I did search but did not find what I was looking for.

the code is:

local table = {"top", "bottom"}
print(table(2))


all I am trying to do is print "bottom" that will be used in with other things.

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 22 February 2013 - 04:58 AM

Split into new topic.

Use [] instead of (). () are used for function calls, [] are used for indexing tables. They are not interchangeable. So, `print(table[2])`. And don't name your tables "table", since you're overwriting the table library.

#3 Coal64

  • New Members
  • 2 posts

Posted 22 February 2013 - 01:25 PM

Thank you.





3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users