# Is there any shorter way i can do this

**URL:** <https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787>\
**Category:** Arcade\
**Created:** [October 6, 2020, 9:39pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787 "2020-10-06T21:39:44Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dreadmask197](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dreadmask197/32/10494_2.png) [@Dreadmask197](https://forum.makecode.com/u/Dreadmask197)\
**Post date:** [October 6, 2020, 9:39pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/1 "2020-10-06T21:39:44Z")

</div>

![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/3/33c7d9c99dfdc28b6b422ab2f9c9125da2dc5006.png)

---

<div class="post-metadata">

**Author:** ![jwunderl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jwunderl/32/5308_2.png) [@jwunderl](https://forum.makecode.com/u/jwunderl)\
**Post date:** [October 6, 2020, 10:05pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/2 "2020-10-06T22:05:36Z")

</div>

hm what do you intend to go inside each if / else branch? Do you just intend to store 20 random values? This would unfortunately be the way in blocks to handle having 18 different branches to the code with unrelated behavior, but if you can give an example of what you intend for it to do on a smaller scale there’s probably a pattern we can use to make it much simpler!

For making each variable, though, any time I see `variable{number}` as variable names I’d be a bit suspicious of it / start to think you might want to use an array; e.g. if you just want to have 20 variables each containing a random number, you could do

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

which will result in list having 20 random values between 1 and 18 (they will be stored in indexes 0-19)

---

<div class="post-metadata">

**Author:** ![Dreadmask197](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dreadmask197/32/10494_2.png) [@Dreadmask197](https://forum.makecode.com/u/Dreadmask197)\
**Post date:** [October 6, 2020, 10:14pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/3 "2020-10-06T22:14:57Z")

</div>

I want 18 random values and put text in them to make a randomized text almost. I’m making a rubiks cube scrambler with notations that are rqndom

---

<div class="post-metadata">

**Author:** ![Dreadmask197](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dreadmask197/32/10494_2.png) [@Dreadmask197](https://forum.makecode.com/u/Dreadmask197)\
**Post date:** [October 6, 2020, 10:19pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/4 "2020-10-06T22:19:35Z")

</div>

> **[Rubiks Cube Scrambler](https://arcade.makecode.com/50050-92721-34637-47879)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

  
Here is the link so you know the extensions and variables I’m using.  
I plan to put it in an `A Button Pressed` block

---

<div class="post-metadata">

**Author:** ![jwunderl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jwunderl/32/5308_2.png) [@jwunderl](https://forum.makecode.com/u/jwunderl)\
**Post date:** [October 6, 2020, 11:06pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/5 "2020-10-06T23:06:51Z")

</div>

Hm, do you just want random strings then? If that’s the case then you would probably want an array of strings, and pick a random index in that; like this example: [Arcade Advanced Stream #10 - Game idea generator](https://forum.makecode.com/t/arcade-advanced-stream-10-game-idea-generator/1549/3)

---

<div class="post-metadata">

**Author:** ![Dreadmask197](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dreadmask197/32/10494_2.png) [@Dreadmask197](https://forum.makecode.com/u/Dreadmask197)\
**Post date:** [October 6, 2020, 11:08pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/6 "2020-10-06T23:08:30Z")

</div>

I’m using 20 “randoms” because a scramble takes up 20 notations

---

<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:** [October 7, 2020, 1:15pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/7 "2020-10-07T13:15:53Z")

</div>

There are several ways that you can do this. How you go about this depends on what you want to do with this information.

- Do you need to keep information on all 20 turns, or do you just need to do something with each turn as it’s created?
- How do you want to display the information about these turns, if at all?
- What do you want to do after the 20 turns have been generated?

For really complex projects, it can be tough to write the code. It helps a lot if you write a plan ahead of time.

Let us know what you’re planning for this program. There are a bunch of us here who will be happy to help you with writing your plan or, afterward, with writing your code.

I love the premise of your program! Looking forward to helping you with it!

---

<div class="post-metadata">

**Author:** ![Dreadmask197](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dreadmask197/32/10494_2.png) [@Dreadmask197](https://forum.makecode.com/u/Dreadmask197)\
**Post date:** [October 7, 2020, 3:29pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/8 "2020-10-07T15:29:50Z")

</div>

I want to make these random words like:  
R2  
Ri  
R  
and those three will be used because that is only the right side of the cube. 6 sides x 3 notations on 1 side is equal to 18 different notations that can be used for scrambles and there has to be 20 notations on a random scramble

all notations:  
L, Li, L2, R, Ri, R2, D, Di, D2, U, Ui, U2, F, Fi, F2, B, Bi, B2

---

<div class="post-metadata">

**Author:** ![Dreadmask197](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dreadmask197/32/10494_2.png) [@Dreadmask197](https://forum.makecode.com/u/Dreadmask197)\
**Post date:** [October 7, 2020, 3:36pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/9 "2020-10-07T15:36:59Z")

</div>

![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/a/ab73c8d93fb02a8392b09475f4f9e73d57dd62f3.png)  
What am I doing wrong? @AlexK @jwunderl

---

<div class="post-metadata">

**Author:** ![Dreadmask197](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dreadmask197/32/10494_2.png) [@Dreadmask197](https://forum.makecode.com/u/Dreadmask197)\
**Post date:** [October 7, 2020, 3:46pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/10 "2020-10-07T15:46:34Z")

</div>

> **[Rubiks Cube Scrambler](https://arcade.makecode.com/17234-40333-23538-87584)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

  
This is what I’m doing so far

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [October 7, 2020, 4:07pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/11 "2020-10-07T16:07:58Z")

</div>

You can’t set a string to a number. (This is the power of Typescript in action)

---

<div class="post-metadata">

**Author:** ![Dreadmask197](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dreadmask197/32/10494_2.png) [@Dreadmask197](https://forum.makecode.com/u/Dreadmask197)\
**Post date:** [October 7, 2020, 4:08pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/12 "2020-10-07T16:08:42Z")

</div>

Then what do I do to make randomized text in a text sprite

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [October 7, 2020, 4:10pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/13 "2020-10-07T16:10:15Z")

</div>

You have to convert the number to a string.

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

---

<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:** [October 7, 2020, 4:10pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/14 "2020-10-07T16:10:34Z")

</div>

_Note_: Original post had a bit of an error in it.

You’re _super close_!

Like @UnsignedArduino said, your `NotationList` is an array of strings, and you’re trying to assign numbers into the array.

You also probably don’t want to change the list of moves. You want a new list instead with some random moves picked from `NotationList`.

You want something like this:

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

Notice I’m passing `ShuffledList` to your function, too.

P.S. I really like your use of comments! Good job in putting a plan together!

---

<div class="post-metadata">

**Author:** ![Dreadmask197](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dreadmask197/32/10494_2.png) [@Dreadmask197](https://forum.makecode.com/u/Dreadmask197)\
**Post date:** [October 7, 2020, 4:14pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/15 "2020-10-07T16:14:48Z")

</div>

What’s the ShuffledList

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [October 7, 2020, 4:14pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/16 "2020-10-07T16:14:59Z")

</div>

Also noting, @AlexK used a single `join _` instead of `convert _ to text`. The `convert _ to text` makes more sense if you are just going to convert one number, but the `join _` is useful if you want to shove a bunch of strings, numbers, etc. together, because it implicitly converts all of the inputs to strings and adds them together. They essentially both do the same.

---

<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:** [October 7, 2020, 4:17pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/17 "2020-10-07T16:17:13Z")

</div>

`ShuffledList` will be a new list with random moves selected from `NotationList`.

So, `NotationList` looks like this:

```auto
R, R1, R2, L, L1, L2, F, F1, F2, D, D1, D2, B, B1, B2, U, U1, U2

```

And `ShuffledList` might look like this:

```auto
D, U2, L, L, F, D2, R, B, F, U, F, R2, L1, F1, F2, B, U2, F1

```

`ShuffledList` will be different each time that loop runs.

---

<div class="post-metadata">

**Author:** ![Dreadmask197](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dreadmask197/32/10494_2.png) [@Dreadmask197](https://forum.makecode.com/u/Dreadmask197)\
**Post date:** [October 7, 2020, 4:20pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/18 "2020-10-07T16:20:06Z")

</div>

The shuffled list is what I want as multiple text sprites

---

<div class="post-metadata">

**Author:** ![Dreadmask197](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dreadmask197/32/10494_2.png) [@Dreadmask197](https://forum.makecode.com/u/Dreadmask197)\
**Post date:** [October 7, 2020, 4:22pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/19 "2020-10-07T16:22:49Z")

</div>

Is there a picture you can add @AlexK?

---

<div class="post-metadata">

**Author:** ![Dreadmask197](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dreadmask197/32/10494_2.png) [@Dreadmask197](https://forum.makecode.com/u/Dreadmask197)\
**Post date:** [October 7, 2020, 4:23pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/20 "2020-10-07T16:23:37Z")

</div>

This is what I have so far

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

[Next page](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787.md?page=2)
