Ask coding questions

← Back to all posts
printing item of table error (has anyone else had this problem?)
JSuser2021

So, what I mean by printing item of table is well, printing a item of table. The code for doing this would usually be:

table = {"a", "value"}
print(table[1])

Which would normally result in printing out the item, but instead, it returns a value. Maybe I could put that into a question.

What value would Replit(or Lua) return?
a. The value you're supposed to get in the first place,
b. the item number,
c. or nil?

Well guess what value it returns

NIL!!!!
EXPLOSIONS, EXPLOSIONS AND MORE EXPLOSIONS!

But seriously, nil is the value I'm going to get whether I like it or not.

But now, there's only one question to answer
and that is:
Have you had the same problem?

Voters
JSuser2021
Comments
hotnewtop
JSuser2021

I'm sure I haven't set one.

SixBeeps

It looks like it's working for me
https://replit.com/@SixBeeps/tablestuffs#main.lua

You haven't set a metatable, right?

JSuser2021

@SixBeeps
does this code work?
table2 = {"a", "b"}
ID = 1
print(table2[ID])