How to create nutrition app with ocr scanner?

Should I use the debug labels exactly as they were shown in one of the screenshots above?

Should it be something like this?

Also when I try this I get the error “undefined” in the debug label. What do I need to fix?

When you evaluate your code, it helps to go line by line (or block by block) and ask yourself “What do I expect to happen?” AND “What actually happens?”

In looking at your code, I would expect the variable called “message” to have no value because you haven’t set one. So when you set the Debug label’s text to the variable “message” and get the error “undefined”, that would be the expected outcome. That variable IS undefined.

The most important block in your code is the “set app variable carbohydrates_100g” block because everything else you’re trying to do depends on that block. So if I were you, I would be setting the Debug’s Text to that variable. And then considering “what value do I expect to see?” That’s going to depend on the JSON response but let’s just say we’re expecting the value 23. Okay, so do we get 23 in the Debug label? Or do we get some other number/word? Or do we get an error/white screen crash?

Once you are sure that the Debug label is getting the right value every time, then you can worry about checking to see if the “carbohydrates_100g” variable is less than or greater than or equal to a certain value.

Edit: I just saw the function you created (WAIT and report). It’s possible that the variable “message” is getting set there but I don’t think it is. You’d have to use a function variable which is different.


Oh, and because you want the Debug label to show the value no matter what, make sure it’s not inside an if block. Put the “set Debug’s Text to” block right below the “set app variable carbohydrates_100g to” block.


So all the debug labels should always be outside an if block?

These are my blocks. The screen still goes white and says that there is an error with the blocks.

That indicates that there’s a problem with your JSON parsing. So I would go back to the formatted JSON in a browser and make sure you are getting the right property.

What barcode value are you using in your Web API URL?

It you’re still using this URL:

Then the “product” property is not a list/array. So you can’t get list item #56 of that property as you’re attempting to do. You should remove the “in list [ ] get # 56” block.

1 Like

Yes, I am using that url.
Is that better?

1 Like

I really like this JSON formatter I just found:

You can paste in the full JSON response on the left side and click Tree Viewer. Then, on the right side, you can search for a property such as “nutriment”, click on “carbohydrates_100g” below it and see the path to that property at the top (object → product → etc.).


When I do the live test the debug label says “value” and the barcode scanner label says “undefined”. What does that mean?

Can someone please help me figure out what the problem still is? I have to finish and submit this project by the end of today. This is all my code so far.

1 Like

If your app keep crashing then you need to localize the problem first. If I were you I would first remove the Get property block all together and assign the app variable carbohydrates_100g a direct value. Then run the app and see if it still crashes.
at least, if it crashes then you know your get property block is OK and if the program worked without this block then you have localized the code with the problem.

Happy Thunking.

1 Like

When I took the get property block out and assigned the direct value of app variable carbohydrates_100g, the app did not crash. And the debug label said “value” after I did a live test. So what would I need to change now?

OK, so firstly, there’s a lot that’s missing with your code. And if I’m not wrong, the deadline is coming closer.
Let’s do it step by step.

Your if not error and if status = 200 is wrong. You’ve done
if not error
if status = 200
(bla bla bla)
else set Error’s text to error.

Here, you are connecting the error display with the event of the status not being 200.
You should actually put it in the else block connected the if not error statement.
In the else block connected to the if status = 200, you should put
set Status’s text to status(not the text ‘status’, the green block.).
Your end result should look like this:

1 Like

Okay, thanks!
So should it be like this?

I know that the barcode scanner does not work on the computer, but the debug label says this even when I try it on my phone:
And it also says undefined in the values label from the debug code:

So what should I do to fix this, because I don’t get the “healthy/ not healthy” value at all.

I tried this type of debugging and I get “value” in the debugging box.
And I’m still not getting the healthy/unhealthy text. Could someone please let me know soon what I need to fix? Sorry, this is just very urgent and I need to get this finished in the next couple of hours.

What have you initialized carbohydrates_100g to? Where have you initialized it? Are you changing the value after every function? What are you comparing again 15.9/16?

Yes I am comparing 15.9/16
This is where I intialized it:

1 Like

Also, you should download the Thunkable Live app and test this. This seemd to be a webpage from which you are we testing.