2

So I'm writing a program for the minecraft mod computercraft. I wanted to know if it was possible to do something like this:

tbl = {}
var = "minecraft:dirt"
tbl[var] = {pos ={0,0,0,1}}

For some reason I feel it doesnt save this table correctly so when I go to do

print(tbl["minecraft:dirt"].pos[4])

it errors

Can you use colons in keys?

bcash8
  • 21
  • 1

1 Answers1

3
tbl = {}
var = "minecraft:dirt"
tbl[var] = {pos ={0,0,0,1}}
print(tbl["minecraft:dirt"].pos[4])

prints 1

This is syntactically correct and should not result in any error message.

The only thing that won't work with colon is the syntactic sugar tbl.minecraft:dirt as Lua names may not contain colons. But if you use it like that tbl["minecraft:dirt"] colon is perfectly fine.

Long story short: Yes you can use colons in table keys.

Piglet
  • 27,501
  • 3
  • 20
  • 43