Hello, I have successfully been able to get JSON data from cloud variables in Firebase. But when i display the data, it shows the data with {" symbols and its all in one line. I want to arrange everything nicely so it looks proper … Below is an example
Without seeing your blocks, there is no way for us to know what you did wrong.
@varunkadapattimnr try this
Actually, i am not using a WebAPI. I am using Firebase to store this data as cloud variables. Here are the screenshots of my code.
You’re taking the Firebase object such as /event1/… and converting it into JSON and then displaying it which is why you see the {…} data. Instead, use a get property of object
block and get the property “eventname” from the cloud variable. Or, you can simplify things and just set label’s text to cloud variable join [cloud variable eventname] “/event1/eventname”.
Hello. This is related to my previous post where once the user presses “Buy Tickets” i want the changed number to reflect only for that one particular event… it should not affect any other event in the app.
For a more detailed understanding, i have attached screenshots below.
Output:
I want to know how to perform math operations using values of the property of object of cloud variable
Thanks!
Please don’t start a new topic related to an existing one. It means that anyone who wants to help you has to search the forums for your first topic, read it, and then come back here to answer your new, related question.
@conroy33 are you able to merge this with How to arrange JSON data in an orderly manner?
@varunkadapattimnr I gave you the answer in the other topic. Is the problem you’re having with this set of blocks displaying Null?
Try setting the label’s text to cloud variable join [cloud variable eventname] [“/event1/remainingtickets”]. You don’t need to use the get property of object block with Firebase. You can just use the full pathname to the property as a text string with the [cloud variable] block or the [set cloud variable] block (if you want to set the value instead of getting it).
I did do the /event1/remainingtickets method… in this picture below… But it’s still not giving me the right output ):
And this is the new output im getting. The “null” value issue was resolved.
P.S. Sorry for creating a new topic… i’m new to this community forum so still figuring thing out
Thank you
I’m not seeing a problem with your newest screenshots but you’re not refreshing the label that displays the number of remaining tickets once the button is clicked. So you’re going to see a value of zero until you do that.
@tatiang Topics are merged. Thanks for flagging!
Yes. Can you add a wait block before the navigate block and see if that allows the label’s text to change from zero?
So i added a wait 2 seconds delay and i saw the number of tickets change to 40 and i bought 10 tickets. So that mathematical part is working!!
But after that when i re enter the screen, the number of tickets again resets to zero for some reason
Labels and other components don’t retain their values when you switch screens. So if you want a label to always display an updated value, you need to refresh the label (in the same way as earlier) when the screen opens. Note that you are uaing a When Screen Starts block which only runs once when that screen is opened for the first time after the app is launched. So in this case, you’ll want to use a When Screen Opens block for the label refresh.
I changed it to when Screen Opens but it only changes the value of the label when i press “Buy Ticket” and then when i come back to the screen it initializes back to zero for some reason and displays 0
If you put these blocks in a When Screen Opens block then the label will display the current value from Firebase when you navigate to that screen.
Can you post a screenshot of the new blocks you added?
I think i found the problem not sure. When i press “Buy tickets” inside firebase when i saw the tree, the data displayed correctly - soldtickets: 5 and remainingtickets: 45
But when i opened the Eutelsat screen , it reinitialised the values to zero and zero. Is that any way to fix this?
Yayayayayayyyyy!!! I found the solution to my problem!
Actually, according to my old logic when i selected the option in the list viewer it was creating the object and then intialising the remaining and soldtickets value to zero. So everytime i clicked on the Eutelsat option, it would initialise the values to zero.
So, i modified it and here is the final working code!
Remaining tickets were 31. After buying the 5 tickets…
Thank you to everyone who guided me through this especially @tatiang