# How do i make it so the text sprite extention can display a specific number that changes based on a condition?

**URL:** https://forum.makecode.com/t/how-do-i-make-it-so-the-text-sprite-extention-can-display-a-specific-number-that-changes-based-on-a-condition/20943
**Category:** Help
**Created:** [June 30, 2023, 4:39pm UTC](https://forum.makecode.com/t/how-do-i-make-it-so-the-text-sprite-extention-can-display-a-specific-number-that-changes-based-on-a-condition/20943 "2023-06-30T16:39:19Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Brainstorm\_Studios](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/brainstorm_studios/32/20476_2.png) [@Brainstorm\_Studios](https://forum.makecode.com/u/Brainstorm_Studios)
#### Post date: [June 30, 2023, 4:39pm UTC](https://forum.makecode.com/t/how-do-i-make-it-so-the-text-sprite-extention-can-display-a-specific-number-that-changes-based-on-a-condition/20943/1 "2023-06-30T16:39:19Z")

</div>

i want to make a HUD with the text sprite extention, but i don’t exactly know how. can someone help me?

---

<div class="post-metadata">

### Author: ![AlexK](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/alexk/32/33339_2.png) [@AlexK](https://forum.makecode.com/u/AlexK)
#### Post date: [July 1, 2023, 11:38pm UTC](https://forum.makecode.com/t/how-do-i-make-it-so-the-text-sprite-extention-can-display-a-specific-number-that-changes-based-on-a-condition/20943/2 "2023-07-01T23:38:16Z")

</div>

You can update a text sprite in an `on update` block if you’re not sure when a value will change. Otherwise, you can use some other sort of event handler, like for a button press, if you know when you want the text sprite to change.

Take a look below for examples of all of these. Press the **A** and **B** buttons to change the text sprites in the middle of the screen.

> **[arcade-text Playground](https://arcade.makecode.com/09257-11078-20247-63261)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

### Author: ![YuHayate](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/yuhayate/32/8275_2.png) [@YuHayate](https://forum.makecode.com/u/YuHayate)
#### Post date: [July 1, 2023, 11:40pm UTC](https://forum.makecode.com/t/how-do-i-make-it-so-the-text-sprite-extention-can-display-a-specific-number-that-changes-based-on-a-condition/20943/3 "2023-07-01T23:40:44Z")

</div>

![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/4/4129c9ab0494831628f7738682b8f5a39260bcf0.png)

use the set(textSprite) text “”  
to change the code it can also use unicode  
and use the convert to text and join  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/b/b359af2c721efe6e88edbcbea00feba1770c9241.png)  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/d/dcb0424970b9d8d05dacb8d277b5d6c794213758.png)  
now if you want to make a number from 1200000 to 1.2m or 1000 to 1k so abbreviate Number function. but you need spriteUtile extension

> **abbreviateNumber function**
>
> ```auto
> 
> function abbreviateNumber(Value: number, Desimal: number) {
> if (1000 <= Math.sqrt(Value **2) && !(1000000 <= Math.sqrt(Value** 2))) {
> return "" + convertToText(roundWithPrecision(Value / 1000, Desimal)) + "K"
> } else if (1000000 <= Math.sqrt(Value **2) && !(1000000000 <= Math.sqrt(Value** 2))) {
> return "" + convertToText(roundWithPrecision(Value / 1000000, Desimal)) + "M"
> } else if (1000000000 <= Math.sqrt(Value **2) && !(1000000000000 <= Math.sqrt(Value** 2))) {
> return "" + convertToText(roundWithPrecision(Value / 1000000000, Desimal)) + "B"
> } else if (1000000000000 <= Math.sqrt(Value **2) && !(1000000000000000 <= Math.sqrt(Value** 2))) {
> return "" + convertToText(roundWithPrecision(Value / 1000000000000, Desimal)) + "T"
> } else if (1000000000000000 <= Math.sqrt(Value **2) && !(1000000000000000000 <= Math.sqrt(Value** 2))) {
> return "" + convertToText(roundWithPrecision(Value / 1000000000000000, Desimal)) + "Qua"
> } else if (1000000000000000000 <= Math.sqrt(Value **2) && !(1e+21 <= Math.sqrt(Value** 2))) {
> return "" + convertToText(roundWithPrecision(Value / 1000000000000000000, Desimal)) + "Qui"
> } else if (1e+21 <= Math.sqrt(Value **2) && !(1e+24 <= Math.sqrt(Value** 2))) {
> return "" + convertToText(roundWithPrecision(Value / 1e+21, Desimal)) + "S"
> } else if (1e+24 <= Math.sqrt(Value **2) && !(1e+27 <= Math.sqrt(Value** 2))) {
> return "" + convertToText(roundWithPrecision(Value / 1e+24, Desimal)) + "Sep"
> } else if (1e+27 <= Math.sqrt(Value **2) && !(1e+30 <= Math.sqrt(Value** 2))) {
> return "" + convertToText(roundWithPrecision(Value / 1e+27, Desimal)) + "Oct"
> } else if (1e+30 <= Math.sqrt(Value **2) && !(1e+33 <= Math.sqrt(Value** 2))) {
> return "" + convertToText(roundWithPrecision(Value / 1e+30, Desimal)) + "Non"
> } else if (1e+33 <= Math.sqrt(Value **2) && !(1e+36 <= Math.sqrt(Value** 2))) {
> return "" + convertToText(roundWithPrecision(Value / 1e+33, Desimal)) + "Dec"
> } else if (1e+36 <= Math.sqrt(Value **2) && !(1e+39 <= Math.sqrt(Value** 2))) {
> return "" + convertToText(roundWithPrecision(Value / 1e+36, Desimal)) + "Und"
> } else if (1e+39 <= Math.sqrt(Value **2) && !(1e+42 <= Math.sqrt(Value** 2))) {
> return "" + convertToText(roundWithPrecision(Value / 1e+39, Desimal)) + "Duo"
> } else if (1e+42 <= Math.sqrt(Value **2) && !(1e+45 <= Math.sqrt(Value** 2))) {
> return "" + convertToText(roundWithPrecision(Value / 1e+42, Desimal)) + "Tre"
> } else if (1e+45 <= Math.sqrt(Value **2) && !(1e+48 <= Math.sqrt(Value** 2))) {
> return "" + convertToText(roundWithPrecision(Value / 1e+45, Desimal)) + "Quat"
> } else if (1e+48 <= Math.sqrt(Value **2) && !(1e+51 <= Math.sqrt(Value** 2))) {
> return "" + convertToText(roundWithPrecision(Value / 1e+48, Desimal)) + "Quin"
> } else if (1e+51 <= Math.sqrt(Value **2) && !(1e+54 <= Math.sqrt(Value** 2))) {
> return "" + convertToText(roundWithPrecision(Value / 1e+51, Desimal)) + "Sexde"
> } else if (1e+54 <= Math.sqrt(Value **2) && !(1e+57 <= Math.sqrt(Value** 2))) {
> return "" + convertToText(roundWithPrecision(Value / 1e+54, Desimal)) + "Septe"
> } else if (1e+57 <= Math.sqrt(Value **2) && !(1e+60 <= Math.sqrt(Value** 2))) {
> return "" + convertToText(roundWithPrecision(Value / 1e+57, Desimal)) + "Octod"
> } else if (1e+60 <= Math.sqrt(Value ** 2)) {
> return "" + convertToText(roundWithPrecision(Value / 1e+60, Desimal)) + "Novem"
> } else {
> return convertToText(roundWithPrecision(Value, Desimal))
> }
> }
> 
> ```

---

<div class="post-metadata">

### Author: ![YuHayate](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/yuhayate/32/8275_2.png) [@YuHayate](https://forum.makecode.com/u/YuHayate)
#### Post date: [July 1, 2023, 11:42pm UTC](https://forum.makecode.com/t/how-do-i-make-it-so-the-text-sprite-extention-can-display-a-specific-number-that-changes-based-on-a-condition/20943/4 "2023-07-01T23:42:19Z")

</div>

i made a better and more user friendly abbreviate Number function, with a better round to decimal function the the one from spriteUtile

> **abbreviateNumber function**
>
> ```auto
> function abbreviateNumber(value: number, Decimals: number) {
> numlist = [
> ["K", "1000"],
> ["M", "1000000"],
> ["B", "1000000000"],
> ["T", "1000000000000"],
> ["Qa", "1000000000000000"],
> ["Qi", "1000000000000000000"],
> ["Sx", "1e+21"],
> ["Sp", "1e+24"],
> ["Oc", "1e+27"],
> ["No", "1e+30"],
> ["Dc", "1e+33"],
> ["Ud", "1e+36"],
> ["Dd", "1e+39"],
> ["Td", "1e+42]"],
> ["Qad", "1e+45"],
> ["Qid", "1e+48"],
> ["Sxd", "1e+51"],
> ["Spd", "1e+54"],
> ["Ocd", "1e+57"],
> ["Nod", "1e+60"],
> ["Vg", "1e+63"]
> ]
> Position = Math.floor((convertToText(value).length - 1) / 3) - 1
> abbr = "" + convertToText(roundToDecimal(value / parseFloat(numlist[Position][1]), Decimals)) + numlist[Position][0]
> return abbr
> }
> 
> ```

> **roundToDecimal function**
>
> ```auto
> function roundToDecimal (num: number, decimalPlaces: number) {
> factor = 10 ** decimalPlaces
> return Math.round(num * factor) / factor
> }
> 
> ```

---

<div class="post-metadata">

### Author: ![YuHayate](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/yuhayate/32/8275_2.png) [@YuHayate](https://forum.makecode.com/u/YuHayate)
#### Post date: [July 3, 2023, 5:02pm UTC](https://forum.makecode.com/t/how-do-i-make-it-so-the-text-sprite-extention-can-display-a-specific-number-that-changes-based-on-a-condition/20943/5 "2023-07-03T17:02:11Z")

</div>

i also made a game with the text sprite extension

> **[CubeStare V1.5.31](https://arcade.makecode.com/47828-46742-47943-49608)**
>
> Fait avec ❤️ dans Microsoft MakeCode Arcade.

---

<div class="post-metadata">

### Author: ![Sarge](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/sarge/32/19590_2.png) [@Sarge](https://forum.makecode.com/u/Sarge)
#### Post date: [July 3, 2023, 5:08pm UTC](https://forum.makecode.com/t/how-do-i-make-it-so-the-text-sprite-extention-can-display-a-specific-number-that-changes-based-on-a-condition/20943/6 "2023-07-03T17:08:23Z")

</div>

That’s great but, I don’t think that’s what @Brainstorm_Studios asked for…

---

<div class="post-metadata">

### Author: ![danger\_kitty](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/danger_kitty/32/32006_2.png) [@danger\_kitty](https://forum.makecode.com/u/danger_kitty)
#### Post date: [July 3, 2023, 5:19pm UTC](https://forum.makecode.com/t/how-do-i-make-it-so-the-text-sprite-extention-can-display-a-specific-number-that-changes-based-on-a-condition/20943/7 "2023-07-03T17:19:38Z")

</div>

You just have to update it when the number changes

---

<div class="post-metadata">

### Author: ![Brainstorm\_Studios](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/brainstorm_studios/32/20476_2.png) [@Brainstorm\_Studios](https://forum.makecode.com/u/Brainstorm_Studios)
#### Post date: [July 4, 2023, 9:36pm UTC](https://forum.makecode.com/t/how-do-i-make-it-so-the-text-sprite-extention-can-display-a-specific-number-that-changes-based-on-a-condition/20943/8 "2023-07-04T21:36:33Z")

</div>

please dont @ me in a conversation that im not a part of. i get a notification and think to myself “this person @ 'ed me, they probably want to talk.” but then when i check the topic, that isn’t the case and the person in question just used my username to talk with someone else. if you want to mention me in a conversation, great, go for it, just please dont use @.

---

<div class="post-metadata">

### Author: ![Sarge](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/sarge/32/19590_2.png) [@Sarge](https://forum.makecode.com/u/Sarge)
#### Post date: [July 5, 2023, 4:07pm UTC](https://forum.makecode.com/t/how-do-i-make-it-so-the-text-sprite-extention-can-display-a-specific-number-that-changes-based-on-a-condition/20943/9 "2023-07-05T16:07:07Z")

</div>

You know @ing someone means _mentioning them_ right? I though this conversation was relevant, but I won’t @ you if it bothers you that much
