problem with comparing strings and table values (not the 'and' operator)

I found out that the problem may lie in the fact that I’m comparing a string (card.value) and a value from a table

    local guesses = { “g”, “kh”, “ng”, “j”, “ch”, “s”, “y”, “d”, “dt”, “th”, “n”,
                        “b”, “bp”, “ph”, “f”, “m”, “r”, “l”, “w”, “h”, “silent” }
 

I assumed that:  textThree.text = guesses[ val ] would return a string, instead it returns: table: 0x100109740

…and this was the problem:

until textTwo ~= card.value and textTwo ~= textOne  

instead should be

until textTwo.text ~= card.value and textTwo.text ~= textOne.text

I was comparing the object with the string. Silly me.


Hi,

I have this problem with a repeat/until loop with multiple check using and.

I wrote this flashcard game in java and I’m translating it into lua. A card is shown, and there are 5 possible answers. All the answers should be different and only one correct. This is the part where I’m checking that the buttons are showing different outcomes, however, at times there are buttons showing the same answer. Anyone that can help?

Lua version -repeat/until-

 if correctButton ~= 1 then repeat local val = math.random(20) textOne.text = guesses[val] until textOne ~= card.value end if correctButton ~= 2 then repeat local val = math.random(20) textTwo.text = guesses[val] until textTwo ~= card.value and textTwo ~= textOne end if correctButton ~= 3 then repeat local val = math.random(20) textThree.text = guesses[val] until textThree ~= card.value and textThree ~= textOne and textThree ~= textTwo end if correctButton ~= 4 then repeat local val = math.random(20) textFour.text = guesses[val] until textFour ~= card.value and textFour ~= textOne and textFour ~= textTwo and textFour ~= textThree end if correctButton ~= 5 then repeat local val = math.random(20) textFive.text = guesses[val] until textFive ~= card.value and textFive ~= textOne and textFive ~= textTwo and textFive ~= textThree and textFive ~= textFour end

…and this was the problem:

until textTwo ~= card.value and textTwo ~= textOne

 

instead should be

until textTwo.text ~= card.value and textTwo.text ~= textOne.text

 

I was comparing the object with the string. Silly me.

…and this was the problem:

until textTwo ~= card.value and textTwo ~= textOne

 

instead should be

until textTwo.text ~= card.value and textTwo.text ~= textOne.text

 

I was comparing the object with the string. Silly me.