Weird problem with tables

Hey guys.
So i’ve got a table called ‘data’, and when i try to print the first value of it, it prints it out as a table, but when i use a variable which equals to one and try and print it, it prints out nil.
This is what i do:



print(data[1].VictimNick)
print(ID)
print(data[ID].VictimNick)


This is the output:



Name
1
nil


Try #ID as it’s probably, somehow, a string.

Worked! I love you…
So why is it with the “#”, didn’t really understand it.

It changes a non-number into a number.

thats true, thank you! :slight_smile:

actually, # is shorthand for string.len
[LUA]
local str = “123”
print( str, #str, str:len(), string.len( str ), (“123”):len() )
print( tonumber( str ) )
–> 123 3 3 3 3
–> 123
[/LUA]

so it only works in this context because the string is one character long, but if it were >9 then you would get unexpected behaviour

so you want to use
[LUA]data[tonumber( ID )].VictimNick[/LUA]
or even better, find out why the id is a string