Just trying to change the readable text on screen. Weird hiccups on android build

So here’s a repost of my last post. It was pointed out that my adding comments in the lua section made it hard to read. 

So it’s a flashcard app where currentCard is the current card the user sees on screen and questionsAndAnswers is the table of questions and answers (ingenious I know haha). The following code is for  my questionsAnsdAnswers table and for when they click to go onto the NEXT card. Also “text” is a native textbox.

My questionsAndAnswers table

[lua]

local questionsAndAnswers = {

{Q = “Question 1: What is 1 + 2?”, A = “Answer 1: equals 3”, location = nil},

{Q = “Question 2: What is 2 + 2?”, A = “Answer 2: equals 4”}

}

[/lua]

Next function

[lua]

print ("this is currentCard:  "…currentCard)

print ("this is current text.text:  "…text.text)

if (currentCard+1 <= #questionsAndAnswers) then

currentCard = currentCard+1

print ("1This is current card now "…currentCard)

print (questionsAndAnswers[currentCard].Q)

–text.text = questionsAndAnswers[currentCard].Q

text.text = (questionsAndAnswers[currentCard].Q)

–markedStatusText.text = “”

print ("this is text.text "…text.text)

print ("printing statement1:  "… text.text)

if (marked[tonumber(string.match (string.sub( text.text, 8 , 13 ), “%d+”))] == true) then

for k, v in pairs( marked ) do

print(k, v)

end

markedStatusText.text = “Marked”

print (“making markedStatusText say marked”)

else 

print (“making markedStatusText become nil”)

markedStatusText.text = “”

end

[/lua]

And here’s terminal readings

[lua]

this is currentCard:  1

this is current text.text:  Question 1: What is 1 + 2? 

1This is current card now 2

Question 2: What is 2 + 2               --*** This is what I want text.text to be

This is text.text Question 1: What is 1 + 2?

printing statement1:  Question 1: What is 1 + 2?

making markedStatusText become nil

[/lua]

So up above in the terminal output I put in a comment with “***”. That is what I want to have text.text show but even when I code the next line, as “text.text = (questionsAndAnswers[currentCard].Q)” I can’t get the correct text to appear

Any ideas are welcome! I even tried to put "text.text == questionsAndAnswers[currentCard].Q " But then corona simulator doesn’t start up saying that it expects “=” where “==” is 

Thanks!

== is a test of equality in “if”, “while” and “repeat” statements or on the right side of an assignment. “=” is an assignment statement.

variable = value

means you are taking the right side of the equal sign and putting the value in the variable. You can’t just have:

variable == value 

doesn’t mean anything since a test to see if variable is equal to value by itself is useless. You can do:

someVariable = variable == value

which says “is variable equal to value”, if yes, assign true to someVariable, if not, assign false.

Rob

Thanks for the explanation Rob, I was trying the “==” out of desperation but at least now I actually understand when to use “==” vs “=”. 

 

Any ideas as to why I can make the print statements show what I want but I can’t get text.text to emulate the result of the prior print statement? (lines 8-12 in next function).

 

Thanks!

Is that the whole code?

Can I just check that the essence of the problem here is that the output of this:

print (questionsAndAnswers[currentCard].Q)

is different to what you see in your text object if you do this:

text.text = (questionsAndAnswers[currentCard].Q)

even though no other code has occurred between those 2 lines to change the value of “currentCard”?

I don’t see anything at all that would be causing that to happen, so I suspect there is something else in your code which you have not pasted here. For instance I don’t see where the display.newText object called text is created (on a separate note I’d recommend giving it a more unique name as it can get confusing given that it also has a property called “text”).  

Yeah that’s what’s so confusing. Everything works fine on corona simulator though. In that “next function” I didn’t leave anything in betweenout and nothing else should be changing the currentCard value. When I get home today I’ll throw in a print statement for the currentCard value after I try to alter text.text and see if it somehow gets imcorrectly changed.

Only other solution I can think of is that maybe the device I’m testing on is slow to process the change I want?

Generally when we hear “It works in the simulator, but not on the device”, it’s usually an error that’s device specific such as trying to load an image when the file name has a case sensitivity problem.

You should examine the device’s console log and see if there are errors.

Rob

== is a test of equality in “if”, “while” and “repeat” statements or on the right side of an assignment. “=” is an assignment statement.

variable = value

means you are taking the right side of the equal sign and putting the value in the variable. You can’t just have:

variable == value 

doesn’t mean anything since a test to see if variable is equal to value by itself is useless. You can do:

someVariable = variable == value

which says “is variable equal to value”, if yes, assign true to someVariable, if not, assign false.

Rob

Thanks for the explanation Rob, I was trying the “==” out of desperation but at least now I actually understand when to use “==” vs “=”. 

 

Any ideas as to why I can make the print statements show what I want but I can’t get text.text to emulate the result of the prior print statement? (lines 8-12 in next function).

 

Thanks!

Is that the whole code?

Can I just check that the essence of the problem here is that the output of this:

print (questionsAndAnswers[currentCard].Q)

is different to what you see in your text object if you do this:

text.text = (questionsAndAnswers[currentCard].Q)

even though no other code has occurred between those 2 lines to change the value of “currentCard”?

I don’t see anything at all that would be causing that to happen, so I suspect there is something else in your code which you have not pasted here. For instance I don’t see where the display.newText object called text is created (on a separate note I’d recommend giving it a more unique name as it can get confusing given that it also has a property called “text”).  

Yeah that’s what’s so confusing. Everything works fine on corona simulator though. In that “next function” I didn’t leave anything in betweenout and nothing else should be changing the currentCard value. When I get home today I’ll throw in a print statement for the currentCard value after I try to alter text.text and see if it somehow gets imcorrectly changed.

Only other solution I can think of is that maybe the device I’m testing on is slow to process the change I want?

Generally when we hear “It works in the simulator, but not on the device”, it’s usually an error that’s device specific such as trying to load an image when the file name has a case sensitivity problem.

You should examine the device’s console log and see if there are errors.

Rob