How to only get the output of a table?

Hello, Im trying to convert what a user has typed to all lowercase then taking that lowercase entry, searhing it through a table, is there anyway to only get the second half of the table and not the whole thing.

This is what I have.

testTable["Jack and Jack"] = "200";

This is what Im trying to do so if you type in “jack and jack” (all lowercase) then it only returns “Jack and Jack = 200”

testTable["jack and jack"] = "Jack and Jack = 200";

it currently returns “jack and jack = Jack and Jack = 200”

print( event.target.text.. " = "..testTable[event.target.text] )                 print(testTable[event.target.text])

This is what I use to search ^

Any ideas thanks

What does this 

print(testTable[event.target.text])

return?

It should return what you are looking for.

it returns “jack and jack = Jack and Jack = 200”

If you want to turn a string all lowercase, you’d use string.lower(s) or s:lower(). Lua is case sensitive when it comes to variable names, so what you are doing is creating two entries in your table: “Jack and Jack” and “jack and jack”. If you plan on creating only one variable, you need to turn the string lowercase before you create the entry.

First, you create Jack and Jack.

testTable["Jack and Jack"] = "200" print(testTable["Jack and Jack"]) --\> output: 200 (string, not a number)

Then you create jack and jack.

testTable["jack and jack"] = "Jack and Jack = 200" print(testTable["jack and jack"]) --\> output: Jack and Jack = 200 (string)

Finally, when you print out event.target.text and the entry, you are printing out:

print( event.target.text.. " = "..testTable[event.target.text] ) -\> event.target.text = "jack and jack" -\> testTable[event.target.text] = "Jack and Jack = 200"

So, your code is really outputting exactly what you wrote. Since you didn’t explicitly state what your expected output is, then I’m just going to guess that your problem is the creation of two entries instead of one, as well as setting the next entry to be “Jack and Jack = 200”, which then leads to odd looking final output when you include the event.target.text… " = " bit.

You were right, thanks for the help, very clear to understand :stuck_out_tongue:

What does this 

print(testTable[event.target.text])

return?

It should return what you are looking for.

it returns “jack and jack = Jack and Jack = 200”

If you want to turn a string all lowercase, you’d use string.lower(s) or s:lower(). Lua is case sensitive when it comes to variable names, so what you are doing is creating two entries in your table: “Jack and Jack” and “jack and jack”. If you plan on creating only one variable, you need to turn the string lowercase before you create the entry.

First, you create Jack and Jack.

testTable["Jack and Jack"] = "200" print(testTable["Jack and Jack"]) --\> output: 200 (string, not a number)

Then you create jack and jack.

testTable["jack and jack"] = "Jack and Jack = 200" print(testTable["jack and jack"]) --\> output: Jack and Jack = 200 (string)

Finally, when you print out event.target.text and the entry, you are printing out:

print( event.target.text.. " = "..testTable[event.target.text] ) -\> event.target.text = "jack and jack" -\> testTable[event.target.text] = "Jack and Jack = 200"

So, your code is really outputting exactly what you wrote. Since you didn’t explicitly state what your expected output is, then I’m just going to guess that your problem is the creation of two entries instead of one, as well as setting the next entry to be “Jack and Jack = 200”, which then leads to odd looking final output when you include the event.target.text… " = " bit.

You were right, thanks for the help, very clear to understand :stuck_out_tongue: