# X thunkable save score, get score from DB

**URL:** <https://community.thunkable.com/t/x-thunkable-save-score-get-score-from-db/603929>\
**Category:** Questions about Thunkable X\
**Tags:** games, tinydb\
**Created:** [June 9, 2020, 6:48am UTC](https://community.thunkable.com/t/x-thunkable-save-score-get-score-from-db/603929 "2020-06-09T06:48:52Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Drean](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@Drean](https://community.thunkable.com/u/Drean)\
**Post date:** [June 9, 2020, 6:48am UTC](https://community.thunkable.com/t/x-thunkable-save-score-get-score-from-db/603929/1 "2020-06-09T06:48:52Z")

</div>

![Untitled](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/9/f/9fe4001395d5d8e88b0da13b29272d434c00324e.png)

i am trying to save the score then get it but its not working please can you help me.

---

<div class="post-metadata">

**Author:** ![browncoatjustice52](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/browncoatjustice52/32/71039_2.png) [@browncoatjustice52](https://community.thunkable.com/u/browncoatjustice52)\
**Post date:** [June 9, 2020, 7:49am UTC](https://community.thunkable.com/t/x-thunkable-save-score-get-score-from-db/603929/2 "2020-06-09T07:49:27Z")

</div>

Can you send your project link…  
Do you use Firebase?

---

<div class="post-metadata">

**Author:** ![gobassky](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/gobassky/32/77019_2.png) [@gobassky](https://community.thunkable.com/u/gobassky)\
**Post date:** [June 9, 2020, 7:52am UTC](https://community.thunkable.com/t/x-thunkable-save-score-get-score-from-db/603929/3 "2020-06-09T07:52:31Z")

</div>

Consider shifting the block “set app bestscore to app score” to above the save block.

 ![9fe4001395d5d8e88b0da13b29272d434c00324e](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/9/9/994b8313fff0ecbea11ce2ffe2e1f8cc516e096f.png)

So that the new score is saved.

Actually with the new Thunkablex implementation, you can use the “Stored” variable type, instead of “app”. This way you just have to treat the variable as normal ones, and no need those “save” and “get” blocks

---

<div class="post-metadata">

**Author:** ![Drean](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@Drean](https://community.thunkable.com/u/Drean)\
**Post date:** [June 9, 2020, 8:52am UTC](https://community.thunkable.com/t/x-thunkable-save-score-get-score-from-db/603929/4 "2020-06-09T08:52:55Z")

</div>

am using phone storage

---

<div class="post-metadata">

**Author:** ![browncoatjustice52](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/browncoatjustice52/32/71039_2.png) [@browncoatjustice52](https://community.thunkable.com/u/browncoatjustice52)\
**Post date:** [June 9, 2020, 8:55am UTC](https://community.thunkable.com/t/x-thunkable-save-score-get-score-from-db/603929/5 "2020-06-09T08:55:32Z")

</div>

ok @Drean

---

<div class="post-metadata">

**Author:** ![Drean](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@Drean](https://community.thunkable.com/u/Drean)\
**Post date:** [June 9, 2020, 9:31am UTC](https://community.thunkable.com/t/x-thunkable-save-score-get-score-from-db/603929/6 "2020-06-09T09:31:55Z")

</div>

thanks i try, nice i never knew about the stored variable type

---

<div class="post-metadata">

**Author:** ![gobassky](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/gobassky/32/77019_2.png) [@gobassky](https://community.thunkable.com/u/gobassky)\
**Post date:** [June 9, 2020, 9:40am UTC](https://community.thunkable.com/t/x-thunkable-save-score-get-score-from-db/603929/7 "2020-06-09T09:40:32Z")

</div>

If you set up the Firebase correctly, you can even safe it on the cloud, by just using the “cloud” variable type. Then your high scores can be shared with all the app instances whoever is using it. The save and get block are completely redundant. 😇

---

<div class="post-metadata">

**Author:** ![Drean](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@Drean](https://community.thunkable.com/u/Drean)\
**Post date:** [June 9, 2020, 9:41am UTC](https://community.thunkable.com/t/x-thunkable-save-score-get-score-from-db/603929/8 "2020-06-09T09:41:25Z")

</div>

can you please show me the code because trying it still not working T\_T

---

<div class="post-metadata">

**Author:** ![gobassky](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/gobassky/32/77019_2.png) [@gobassky](https://community.thunkable.com/u/gobassky)\
**Post date:** [June 9, 2020, 1:42pm UTC](https://community.thunkable.com/t/x-thunkable-save-score-get-score-from-db/603929/9 "2020-06-09T13:42:25Z")

</div>

Here… based on your blocks, I tried to replicate the flow. I would do it this way, only need one extra step to initialize the stored variable the first time and assign it with a value.

 ![Clipboard04](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/d/1/d146745a30d15feb40ca77caf8776bca5d166f67.jpeg)

---

<div class="post-metadata">

**Author:** ![Drean](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@Drean](https://community.thunkable.com/u/Drean)\
**Post date:** [June 9, 2020, 2:06pm UTC](https://community.thunkable.com/t/x-thunkable-save-score-get-score-from-db/603929/11 "2020-06-09T14:06:22Z")

</div>

sadly not working T\_T and also tried removing the set stored bestscore to 0 because i want when the app reopens the old highest score shown.

i would love to try firebase but i have to change a lot of things and make a new screen for creating an account and logining in, it would be a hard.

---

<div class="post-metadata">

**Author:** ![gobassky](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/gobassky/32/77019_2.png) [@gobassky](https://community.thunkable.com/u/gobassky)\
**Post date:** [June 9, 2020, 2:28pm UTC](https://community.thunkable.com/t/x-thunkable-save-score-get-score-from-db/603929/12 "2020-06-09T14:28:11Z")

</div>

The if statement to set the bestscore to zero is meant only for the first time (when the variable is “null” means it was never assigned before). The subsequent times the screen is opened, it will contain the last stored value on the phone memory. So it is essential.

Can you try one more thing? remove the “else” from the screen1 open block. and put the label block below the if statement (not within). Like this you will initialise the variable and put in value, then show it on the label.

If not, got to look at your blocks as a whole to find out what’s wrong.

---

<div class="post-metadata">

**Author:** ![Drean](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@Drean](https://community.thunkable.com/u/Drean)\
**Post date:** [June 11, 2020, 7:24am UTC](https://community.thunkable.com/t/x-thunkable-save-score-get-score-from-db/603929/13 "2020-06-11T07:24:59Z")

</div>

the problem is its not even saving the score in game after you die the score is not saved in the highscore text

---

<div class="post-metadata">

**Author:** ![Drean](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@Drean](https://community.thunkable.com/u/Drean)\
**Post date:** [June 11, 2020, 7:25am UTC](https://community.thunkable.com/t/x-thunkable-save-score-get-score-from-db/603929/14 "2020-06-11T07:25:39Z")

</div>

i used mit app inventor before and i am sure about the code

---

<div class="post-metadata">

**Author:** ![gobassky](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/gobassky/32/77019_2.png) [@gobassky](https://community.thunkable.com/u/gobassky)\
**Post date:** [June 11, 2020, 8:34am UTC](https://community.thunkable.com/t/x-thunkable-save-score-get-score-from-db/603929/15 "2020-06-11T08:34:29Z")

</div>

I migrated from MIT AI also … somethings are sequenced differently. ThunkableX made changes to accommodate iOS implementations. So I wouldn’t assume that.

Its Ok if you do not wish to show other parts of your program. You can use another label to track your “app score” variable at every juncture to find where is the problem. That is how I debug my apps to see exactly where the value was dropped.

---

<div class="post-metadata">

**Author:** ![Drean](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@Drean](https://community.thunkable.com/u/Drean)\
**Post date:** [June 12, 2020, 5:43am UTC](https://community.thunkable.com/t/x-thunkable-save-score-get-score-from-db/603929/16 "2020-06-12T05:43:47Z")

</div>

i dont understand how to rack with another label.

i switched to firebase

 ![Untitled](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/7/e/7eea9acf05a5c11892ce402d74f11a3fae561c95.png)

still not working T\_T

---

<div class="post-metadata">

**Author:** ![gobassky](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/gobassky/32/77019_2.png) [@gobassky](https://community.thunkable.com/u/gobassky)\
**Post date:** [June 12, 2020, 6:53am UTC](https://community.thunkable.com/t/x-thunkable-save-score-get-score-from-db/603929/17 "2020-06-12T06:53:58Z")

</div>

Ok. realtime DB blocks are also asynchronous. Meaning, depending on the speed of the internet, your realtime DB save block may not have been done before the function rungame. Since you have the Firebase set up, you can use the “cloud” type variable, and treat it just like any other variable.

If it is still not working, would you mind sharing the app for mixing so we can take a closer look?

---

<div class="post-metadata">

**Author:** ![Drean](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@Drean](https://community.thunkable.com/u/Drean)\
**Post date:** [June 17, 2020, 1:22pm UTC](https://community.thunkable.com/t/x-thunkable-save-score-get-score-from-db/603929/18 "2020-06-17T13:22:16Z")

</div>

finally i got the score but its a global score how to make each account created has his own personal high score ?

---

<div class="post-metadata">

**Author:** ![ioannis](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/ioannis/32/146956_2.png) [@ioannis](https://community.thunkable.com/u/ioannis)\
**Post date:** [November 8, 2024, 11:25am UTC](https://community.thunkable.com/t/x-thunkable-save-score-get-score-from-db/603929/19 "2024-11-08T11:25:39Z")

</div>


