Using tables to store references

Hello, I am wondering if I could fill a table with references. I am not good at asking questions and giving good detail so I will show an example and hopefully someone will understand me.

I want to set up a table that will display words but I have images for each letter so this table should read each letter individually. Each letter should be referenced by a number, ex: a = 0, b = 1, c = 2, etc… In this example I am wanting the table to store APPLE (0,15,15,11,4) and PEARS {15,4,0,17,18).

[blockcode]
local puzzles = {}
puzzles[1] = {{0,15,15,11,4},
{15,4,0,17,18},}
[/blockcode]

My question really is, how do I store a as 0 and p as 15 etc, but still being able to print the word?

I know this may be a little vague because I am very new but any questions I will be sure to answer to the best of my ability. Thanks in advance for any input! [import]uid: 50511 topic_id: 8818 reply_id: 308818[/import]

I’m not sure if this is what you’re asking for, but I’ll give it a shot.

For your APPLE and PEARS tables, you could do this:

[blockcode]
local puzzles = {
{ A = 0, P = 15, L = 11, E = 4 },
{ P = 15, E = 4, A = 0, R = 17, S = 18 }
}

print( puzzles[1][‘P’] )

– terminal output: 15
[/blockcode]

Another thing you can do is create a table that holds each letter of the alphabet and then just point to the index you want, depending on the letter, depending on what letter you need.

Hope that helps! [import]uid: 52430 topic_id: 8818 reply_id: 32400[/import]

Thanks for the help Jonathan. Your explanation gets me around one mental block I could not figure out and answers the question of being able to make declarations inside a table. So, with our advice, do you think it to be possible to do something like this:

[blockcode]
local alphabet= {{A=0}, {P = 15}, {L = 11}, {E = 4},}
local puzzles = {}
puzzles[1] = {{alphabet[1], alphabet[2], alphabet[3], alphabet[4],}
print(puzzles[1])

–terminal output = APLE
[/blockcode]

I like to approach things theoretically first so I am thinking this may possibly work even if more complications are added in. [import]uid: 50511 topic_id: 8818 reply_id: 32473[/import]

Thanks for the help Jonathan. Your explanation gets me around one mental block I could not figure out and answers the question of being able to make declarations inside a table. So, with our advice, do you think it to be possible to do something like this:

[blockcode]
local alphabet= {{A=0}, {P = 15}, {L = 11}, {E = 4},}
local puzzles = {}
puzzles[1] = {{alphabet[1], alphabet[2], alphabet[3], alphabet[4],}
print(puzzles[1])

–terminal output = APLE
[/blockcode]

I like to approach things theoretically first so I am thinking this may possibly work even if more complications are added in. [import]uid: 50511 topic_id: 8818 reply_id: 32475[/import]

Thanks for the help Jonathan. Your explanation gets me around one mental block I could not figure out and answers the question of being able to make declarations inside a table. So, with our advice, do you think it to be possible to do something like this:

[blockcode]
local alphabet= {{A=0}, {P = 15}, {L = 11}, {E = 4},}
local puzzles = {}
puzzles[1] = {{alphabet[1], alphabet[2], alphabet[3], alphabet[4],}
print(puzzles[1])

–terminal output = APLE
[/blockcode]

I like to approach things theoretically first so I am thinking this may possibly work even if more complications are added in. [import]uid: 50511 topic_id: 8818 reply_id: 32476[/import]

Thanks for the help Jonathan. Your explanation gets me around one mental block I could not figure out and answers the question of being able to make declarations inside a table. So, with our advice, do you think it to be possible to do something like this:

[blockcode]
local alphabet= {{A=0}, {P = 15}, {L = 11}, {E = 4},}
local puzzles = {}
puzzles[1] = {{alphabet[1], alphabet[2], alphabet[3], alphabet[4],}
print(puzzles[1])

–terminal output = APLE
[/blockcode]

I like to approach things theoretically first so I am thinking this may possibly work even if more complications are added in. [import]uid: 50511 topic_id: 8818 reply_id: 32477[/import]

Thanks for the help Jonathan. Your explanation gets me around one mental block I could not figure out and answers the question of being able to make declarations inside a table. So, with our advice, do you think it to be possible to do something like this:

[blockcode]
local alphabet= {{A=0}, {P = 15}, {L = 11}, {E = 4},}
local puzzles = {}
puzzles[1] = {{alphabet[1], alphabet[2], alphabet[3], alphabet[4],}
print(puzzles[1])

–terminal output = APLE
[/blockcode]

I like to approach things theoretically first so I am thinking this may possibly work even if more complications are added in. [import]uid: 50511 topic_id: 8818 reply_id: 32478[/import]

edit [import]uid: 50511 topic_id: 8818 reply_id: 32474[/import]