I have an integer field in one of my collections and I am pulling the info just fine and displaying it in a label. But I cannot add the new points earned during the turn into the label with the existing score pulled from the database.
I have an integer field in one of my collections and I am pulling the info just fine and displaying it in a label. But I cannot add the new points earned during the turn into the label with the existing score pulled from the database.
I'm not 100% sure where you want to add new points.. can you provide more details what you are trying to do?
Ya. Basically I have a layout that displays the score of the current game in a label. The score is grabbed from a field in my "game info" collection I have on my Appery DB. As the player plays their turn they accumulate new points and I want to add those new points to the existing label that is displaying the points from the database.
Hi Michael,
You can read Label text using the "text" function:
codevar currentScore = Appery("labelName").text();/code
Use it to change Label text:
codeAppery("labelName").text(currentScore + points);/code
That is what I am doing now but it isn't working. I get an "undefined" exception and then I tried to used parseFloat so I could add the two integers but I get a "NaN" exception. Would it be easier if the player score field in the database collection was a string rather than an integer?
This is my code I am using now:
var player1CurrScore = Appery('player1Score_lbl').text();
var player1NewScore = currTurnScore + player1CurrScore;
Appery('player1Score_lbl').text(player1NewScore);
I also tried:
var player1CurrScore = Appery('player1Score_lbl').text();
var player1CurrentScore = parseFloat(player1CurrScore);
var player1NewScore = currTurnScore + player1CurrentScore;
Appery('player1Score_lbl').text(player1NewScore);
I am implementing all of this in a function that is being called on a button click where everything else in the button click function is working properly. Just having issues with this one. ![]()
What text do you store in Label? IS there numbers only or you store there a text, too?
Try the following instead of the second line:
codevar player1CurrentScore = parseFloat(player1CurrScore.trim());/codeto delete spaces in the beginning and in the end of the line.
I'm still getting the NaN exception. The only thing I did was create a get_game_info service and then data mapped the value from the response to the player1Score_lbl. The current value is 0 in the database and the label displays it perfectly, but as soon as I try to update it I get the NaN exception.
It's difficult to say where the problem lies.
Probably in "player1Score_lbl" component there is a text that is not a float number.
Prabably in "currTurnScore" variable there is a string, not number.