# How to create nutrition app with ocr scanner?

**URL:** <https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955>\
**Category:** Questions about Thunkable X\
**Created:** [February 21, 2021, 5:28pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955 "2021-02-21T17:28:00Z")\
**Posts on this page:** 20\
**Page:** 8

<div class="post-metadata">

**Author:** ![celebytes20212iy4](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@celebytes20212iy4](https://community.thunkable.com/u/celebytes20212iy4)\
**Post date:** [March 13, 2021, 4:52pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/142 "2021-03-13T16:52:50Z")

</div>

These are all of my blocks:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/2/1/21536df7ec912366c67077aecd53ef64a97f90b2.png)

---

<div class="post-metadata">

**Author:** ![codeswept](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/codeswept/32/87755_2.png) [@codeswept](https://community.thunkable.com/u/codeswept)\
**Post date:** [March 13, 2021, 4:53pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/143 "2021-03-13T16:53:46Z")

</div>

You should also have some code to display the status of the GET from the API.

---

<div class="post-metadata">

**Author:** ![celebytes20212iy4](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@celebytes20212iy4](https://community.thunkable.com/u/celebytes20212iy4)\
**Post date:** [March 13, 2021, 4:54pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/144 "2021-03-13T16:54:00Z")

</div>

I tried a live test on my phone, it doesn’t actually tell me what the error is, the screen just turns white and it says “there is an error with your blocks”.

---

<div class="post-metadata">

**Author:** ![celebytes20212iy4](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@celebytes20212iy4](https://community.thunkable.com/u/celebytes20212iy4)\
**Post date:** [March 13, 2021, 4:56pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/145 "2021-03-13T16:56:28Z")

</div>

Thanks! But I’m actually not sure how to add the status of the GET from the API.

---

<div class="post-metadata">

**Author:** ![codeswept](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/codeswept/32/87755_2.png) [@codeswept](https://community.thunkable.com/u/codeswept)\
**Post date:** [March 13, 2021, 4:59pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/146 "2021-03-13T16:59:23Z")

</div>

Say the carb value is 15… That is neither smaller than 12.5 nor bigger than 19. You should change 12.5 to 18.9.

**EDIT: You can also have another statement to se the text of a label if the carbs value is bigger than 12.5 and smaller than 19. You can use an and block for that.**

---

<div class="post-metadata">

**Author:** ![codeswept](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/codeswept/32/87755_2.png) [@codeswept](https://community.thunkable.com/u/codeswept)\
**Post date:** [March 13, 2021, 5:03pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/147 "2021-03-13T17:03:55Z")

</div>

That is easy…

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/8/7/87e5b7e6c70ede5433c2832e33eb02c45794bbed.png)

All this debugging is important.

---

<div class="post-metadata">

**Author:** ![celebytes20212iy4](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@celebytes20212iy4](https://community.thunkable.com/u/celebytes20212iy4)\
**Post date:** [March 13, 2021, 5:24pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/148 "2021-03-13T17:24:54Z")

</div>

Okay thank you! Is this correct?

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/2/1/215b0d530b4d556dbfa459442c8fe39ea8dbd34b.png)

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [March 13, 2021, 5:47pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/149 "2021-03-13T17:47:08Z")

</div>

One problem you’re going to have is that you’re not setting the value of the variable “carbs” to the actual property “carbohydrates\_100g”. You’re setting a label to that value… but you need to store it in a variable instead. If you set the variable “carbs” to the value the property returns (with the “get property of object” block), you can then use that variable elsewhere in your code, as you’ve done.

If you want to display the number of carbs, first set the variable to that value and _then_ set GetButtonText’s Text to “app variable carbs”.

---

<div class="post-metadata">

**Author:** ![celebytes20212iy4](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@celebytes20212iy4](https://community.thunkable.com/u/celebytes20212iy4)\
**Post date:** [March 13, 2021, 7:08pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/150 "2021-03-13T19:08:08Z")

</div>

I changed the variable name, but it still gives me an error with the blocks, but it does not tell me what the error is.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/0/00aa6e26261fa8abc7969bd30abb9d3e08843c9c.png)

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [March 13, 2021, 7:33pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/151 "2021-03-13T19:33:36Z")

</div>

Watch this:

~~[https://youtu.be/X91egqguwn8](https://youtu.be/X91egqguwn8)~~

---

<div class="post-metadata">

**Author:** ![celebytes20212iy4](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@celebytes20212iy4](https://community.thunkable.com/u/celebytes20212iy4)\
**Post date:** [March 13, 2021, 7:40pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/152 "2021-03-13T19:40:21Z")

</div>

Okay! So is this how I set it to the value?  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/d/2/d2c0e11fa9511e104b88524e44c510394d079ed9.png)

Even when I tried this it shows an error with the blocks.

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [March 13, 2021, 8:13pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/153 "2021-03-13T20:13:19Z")

</div>

I guess that video covered initializing variables but not setting their values.

By the way, I’m just Googling _variables thunkable_. You can do the same. There are lots of tutorial videos. Also, the Thunkable documentation is usually helpful: [Variables Blocks | Thunkable Docs](https://docs.thunkable.com/variables).

This is probably a better video for you:

[![](https://img.youtube.com/vi/-7NHaSJACp8/maxresdefault.jpg "How to Initialize, Set, and Display Variables in Thunkable X") ](https://www.youtube.com/watch?v=-7NHaSJACp8)

---

<div class="post-metadata">

**Author:** ![celebytes20212iy4](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@celebytes20212iy4](https://community.thunkable.com/u/celebytes20212iy4)\
**Post date:** [March 13, 2021, 8:38pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/154 "2021-03-13T20:38:09Z")

</div>

I’m not really understanding what setting the value is, because the video didn’t seem to be mentioning that, and I could not find it in the docs either.

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [March 13, 2021, 8:58pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/155 "2021-03-13T20:58:40Z")

</div>

From the documentation:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/e/2/e2ab6958b24156bd6454707378fb4e83c3085fed.png)

Also, at the 5:59 mark in the video, @darren shows how to set a variable value.

The point is, if you want to use a variable in your code, you need to first set it’s value. And more importantly for your project, when you get the property of a JSON object, you need to set that value to be attached to a variable using the “set” block.

So you need a “set app variable carbs to” block to the immediate left of the “get property of object [carbohydrates\_100g]” block.

---

<div class="post-metadata">

**Author:** ![celebytes20212iy4](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@celebytes20212iy4](https://community.thunkable.com/u/celebytes20212iy4)\
**Post date:** [March 13, 2021, 9:04pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/156 "2021-03-13T21:04:36Z")

</div>

Okay. So after adding that do I remove the “set variable” block above it?

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/6/f/6fdc1562d627a29cc85c21924940996fa61c0c84.png)

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [March 13, 2021, 9:23pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/157 "2021-03-13T21:23:24Z")

</div>

Yes… but I don’t understand why you’re using different variables below that. When you set the variable “CeleBytes” (whatever that is), your next step is to check the value of the variabe “carbohydrates\_100g”. Why? Why not just use the same variable for both? In other words, set “carbohydrates\_100g” to “get property of object…”

Otherwise, it’s like you’re doing math this way:

set x to 35  
if y \< 18.9  
…

You want your code to work like this:

set x to 35  
if x \< 18.9

The “x” and “y” are the variable names. You need consistency.

---

<div class="post-metadata">

**Author:** ![celebytes20212iy4](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@celebytes20212iy4](https://community.thunkable.com/u/celebytes20212iy4)\
**Post date:** [March 13, 2021, 9:28pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/158 "2021-03-13T21:28:11Z")

</div>

Oh, I’m really sorry. When I took the first block it was set to the name “celebytes” and I forgot to change it “carbohydrates\_100g”.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/9/4/94817357e844822448433d49417c081138aeee21.png)

---

<div class="post-metadata">

**Author:** ![celebytes20212iy4](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@celebytes20212iy4](https://community.thunkable.com/u/celebytes20212iy4)\
**Post date:** [March 13, 2021, 9:30pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/159 "2021-03-13T21:30:53Z")

</div>

These are all my blocks. Is there still an error because when I tried to scan a barcode it told me there was an eror with the blocks again.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/8/6/86a3b621716904a3a318624463ef6a191caf3fc4.png)

---

<div class="post-metadata">

**Author:** ![celebytes20212iy4](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@celebytes20212iy4](https://community.thunkable.com/u/celebytes20212iy4)\
**Post date:** [March 13, 2021, 9:41pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/160 "2021-03-13T21:41:34Z")

</div>

Is there something wrong with the way I have parsed?

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [March 13, 2021, 9:54pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/161 "2021-03-13T21:54:33Z")

</div>

The way to troubleshoot your code is to use labels to display intermediate values. So each time you set a variable, you should check its value. You can use Wait blocks to pause your app and check each value. That should help pinpoint where the mistake is.

[Previous page](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955.md?page=7)

[Next page](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955.md?page=9)
