Why does this print 0? I really don't understand why.
1 | local kRef = { |
2 | [ "w" ] = Enum.KeyCode.W, |
3 | [ "a" ] = Enum.KeyCode.A, |
4 | [ "s" ] = Enum.KeyCode.S, |
5 | [ "d" ] = Enum.KeyCode.D, |
6 | [ "space" ] = Enum.KeyCode.Space |
7 | } |
8 | print (#kRef) |
#keyRef
printed 0, because of how the keys are stored. In order to fix this, you should remove the dictionary's indexes and make it a normal table.1 | local kRef = { |
2 | Enum.KeyCode.W, |
3 | Enum.KeyCode.A, |
4 | Enum.KeyCode.S, |
5 | Enum.KeyCode.D, |
6 | Enum.KeyCode.Space |
7 | } |
8 | print (#kRef) --> 5 |
01 | local kRef = { |
02 | [ "w" ] = Enum.KeyCode.W, |
03 | [ "a" ] = Enum.KeyCode.A, |
04 | [ "s" ] = Enum.KeyCode.S, |
05 | [ "d" ] = Enum.KeyCode.D, |
06 | [ "space" ] = Enum.KeyCode.Space |
07 | } |
08 |
09 | --If you want to print all the table's contents, use a loop: |
10 | for i, v in pairs (kRef) do |
11 | print (v) |
12 | end |