Hi, I am making an app that requires adding a certain number of points equal to the number given in a text input box. Now that’s not possible because text input converts it into a string. Please answer if you know any solution!
Try the following:
as long as you enter a number, it will work. So, it would be best if you use “keyboard type” NUMERIC from the advanced features for the text box.
But the problem is that when I push it to firebase, it turns it into a string
That should not be a problem. If you are using the value in your app, when you retrieve the value from firebase, you will need to do the same thing, add zero to the variable or multiply by one.
In your blocks screenshot, you’re adding a text string to a text string. Where are you converting to a number by adding zero?
yeah that’s my question, do you know how to convert it?
The last block should say “from Point Value - Add A Reading set Text to app TotalPoint - AddAReading + from Point Value - Add A Reading get Text + 0”
Here’s an example: Trying to add number from Text Input - #2 by actech
Use the + and 0 blocks in the Math drawer:
Are you still getting “NaN”?
What happens when you check the values of the two green error blocks using labels? What are those values?
If you want to share the link to your project, I can take a look at it.
Sure here is the link! https://x.thunkable.com/copy/1ec7b11ff06df4010279c1e4752678ec
keep in mind that the ui hasn’t been worked on
You only converted ONE of the two strings to a number. Originally, you had string+string=NaN. Now you have string+number=NaN. You need number+number=number.
Add a + 0 here:
Yep, that should have worked. If you set text labels to the two variable values and to their values with zero added, what do you get?
It gave a NaN value again
I’m not sure you’re understanding what I suggested. I have a hard time believing that the math functions in Thunkable are broken (asin notwithstanding) or that adding zero to a text string doesn’t convert it to a number.
So the only other thing that could be causing “NaN” to appear is that your text strings are not valid numbers. For example, it’s possible that having a space or a punctuation mark within the string will invalidate it even when adding zero to it.
So the next step should be to create two labels on the screen. They should be different label components but I’ve shown them as the same in this screenshot:
The idea is to generate two results, both bookended by Xs. So for example, if you see something like…
…then you know it’s a valid string to convert to a number by adding zero to it.
But if you see…
X 5489X then there’s potentially a problem because your string is " 5489" with a leading space.
And if you see…
XX then you know the database Get block failed because your string is “”.
Also, what are your green error blocks showing if you add them to labels so you can see their value?
This type of troubleshooting is really common with Thunkable (and any programming language/environment) so if you’re new to Thunkable, these are good skills to start using.