I have this script where I choose a random number, then transfer it to a letter using this table. Should I be using the [1] = 'A'
or the 'N'
?
01 | _G.alphabet = { |
02 | [ 1 ] = 'A' , |
03 | [ 2 ] = 'B' , |
04 | [ 3 ] = 'C' , |
05 | [ 4 ] = 'D' , |
06 | [ 5 ] = 'E' , |
07 | [ 6 ] = 'F' , |
08 | [ 7 ] = 'G' , |
09 | [ 8 ] = 'H' , |
10 | [ 9 ] = 'I' , |
11 | [ 10 ] = 'J' , |
12 | [ 11 ] = 'K' , |
13 | [ 12 ] = 'L' , |
14 | [ 13 ] = 'M' , |
15 | 'N' , |
I would go with the N and below since you're just going after random letters. Unless a index value is defined like with A-M, then the index value will go from 1 to 2 to 3, etc.
How you can have the table spit out a random letter would be a table like below;
1 | _G.alphabet = { 'A' , 'B' , 'C' , 'D' , 'E' , 'F' , 'G' , 'H' , 'I' , 'J' , 'K' , 'L' , 'M' , 'N' , 'O' , 'P' , 'Q' , 'R' , 'S' , 'T' , 'U' , 'V' , 'W' , 'X' , 'Y' , 'Z' } |
And then with that, you can use the math.random() function to randomly select the letter in this table, unless the table has pre-defined index values (["Test"] = true
).
To have it randomly select a value you can do;
1 | --The script should go TableNameHere[Within The Brackets Is Where The Index Value Goes] |
2 | --And # can help with tables to find out how many values are in the list. |
3 | print (_G.alphabet [ math.random( 1 ,#_G.alphabet) ] ) |
So I'll break this down a little bit more
1 | print () --How else will you know the letter |
2 | print (_G.alphabet) --Start to have it look at the table. |
3 | print (_G.alphabet [ ] ) --Make sure you have brackets for index value. |
4 | print (_G.alphabet [ math.random() ] ) --Get math.random ready to random select. |
5 | print (_G.alphabet [ math.random( 1 , #_G.alphabet) ] ) --1 is the first value of the index, # will get the number of values in the table |
So it should print out A or C or G or T or M or Z etc...