Q: How to use variable to search in table Lua I am stuck on this small section of my Lua program.
currently I have created a table named GPUtable, the keys are GPU Names and the values are Shader core counts. I have used io.write() to create a user input prompt to input a name of a GPU. I would like to use this input (using choice = io.read()) to search the table and print the shader core count.
for example if the user types HD 7950 I would like print(GPUtable[choice]) to print the shader cores and not nil (error).
any help is appreciated

A: If your table keys are indeed the GPU names such as the HD 7950, then indexing it with sqaure brackets will give you what you are looking for. Without any extra code it is hard to diagnose your issue.
GPUTable = { ['HD 7950'] = 1792, ['GTX 1080'] = 2560 }
print(GPUTable[io.read()])

Try running this in your emulator, it should work flawlessly. Your issue could be between receiving the info and indexing. Make sure that the key is a string and is not being changed when it is indexed. Check that your variable names are correct and that you are not trying to use a local variable. It may help to print the 'choice' variable as you are indexing to check for that.
