# 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:** 2

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

</div>

On the “screen gamepad thing” it says, `(object Object)`

---

<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:28pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/22 "2020-10-07T16:28:16Z")

</div>

Got it.

You have this block in your code:

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

When you join the array into one long string, you lose the ability to read individual items in the array easily.

You’ll want a few things, I think, to accomplish what you’re trying to do.

- You’ll want to process the array in your function, instead of trying to do something with that really long string. Because functions cannot accept arrays as parameters (not yet, anyway), you can just work with the `ShuffledList` variable inside of your function.
- You’ll also want to create an array of sprites if you haven’t done so already. That way, you’ll be able to work with a specific sprite in the array and a specific item from `ShuffledList` within a loop.

Something like this:

```auto
function MakeTheTextSpritePositionAndStuff() {
    for index from 0 to 19 {
        currentMove = ShuffledList[index]
        currentSprite = MyCoolSpriteList[index]
        // Then, do something with the sprite, like write text in 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, 4:31pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/23 "2020-10-07T16:31:03Z")

</div>

What is current move and current sprite? I don’t know Javascript and only do block coding

---

<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:32pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/24 "2020-10-07T16:32:02Z")

</div>

This is really confusing right now

---

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

</div>

I know; I can’t write that in Blocks because it’s not real code. 🙂

`currentMove` and `currentSprite` are just new variables. Their values change each time you go through the loop. It’s usually easier to create new variables when you’re working with locations in an array, rather than using those _really_ long array blocks each time you change an item in an array.

---

<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:35pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/26 "2020-10-07T16:35:03Z")

</div>

You’re writing some _really_ complex code! Be patient; you’ll get it. Keep asking questions!

---

<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:36pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/27 "2020-10-07T16:36:16Z")

</div>

Here’s an example. It’s a little simpler than what I was suggesting above.

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

A few things to notice here:

- Notice that `ShuffledList` has 20 items in it, numbered 0 to 19. You can make `ShuffledList` as long as you want; it does not have to match the size of `NotationList`.
- Related to the previous point, `NotationList` has 18 items in it, numbered 0 to 17. I changed the numbers for your `pick random` call to reflect that. (Remember that the first element in an array is item #0.)
- After I create my new list in the loop, I call a new function to process the list.

Here’s `myFunction`. I took the idea that you have in `MakeTheTextSpritePositionAndStuff` as a guide to give you an idea of what you could do.

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

With each pass through the loop, we create a new text sprite and then place it at a particular position on the screen, depending on where we are in the loop. Inside of that loop, you could set other properties on the text sprite if you want.

This is just an example of what you could do, based on your existing code. Give it a try; see what you come up with.

---

<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, 5:00pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/28 "2020-10-07T17:00:25Z")

</div>

I restarted some stuff and deleted some blocks. Then, I went into JavaScript and tried some things out. After that, I went back to blocks and then edited what you told me to do and got this

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

---

<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, 5:23pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/29 "2020-10-07T17:23:10Z")

</div>

Good job!

You can see all of your items from `ShuffledList` on your screen.

Well … a lot of them, anyway. 🙂

Whadya think? Do you have enough information to continue with your plan, or do you still have some questions?

---

<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, 5:26pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/30 "2020-10-07T17:26:12Z")

</div>

I’m going to go and change the font size and the problem is seeing why all the text is diagonal

---

<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, 5:29pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/31 "2020-10-07T17:29:32Z")

</div>

![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/f/f4e4a2c0da8e7f9e444ec1124cf7aa5b6d895195.png)  
Do you know why this is happening?  
nvm figured it out

---

<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, 5:50pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/32 "2020-10-07T17:50:18Z")

</div>

Do you know how to get rid of the diagonal parts on the screen?

---

<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, 7:45pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/33 "2020-10-07T19:45:46Z")

</div>

Yes; more importantly, though, how do _you_ want them to look? You have 20 sprites with instructions. How do you want them arranged on the screen?

---

<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, 8:21pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/34 "2020-10-07T20:21:03Z")

</div>

Maybe like this:  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/3/35f7bf478f062ac9f1d6b3a53f85ecfa76a322b4.png)  
I want them to be in like a row and column kind of thing. with the notations in order. Kinda like this but it’s not accurate to what I’m thinking.

---

<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, 9:16pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/35 "2020-10-07T21:16:26Z")

</div>

![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/c/c5bd5de3920d0a3c60c59e1195a70fa36b31ef72.png)  
The Math isn’t good enough yet @AlexK! Getting close!! Do you know what to do?

---

<div class="post-metadata">

**Author:** ![jacob\_c](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jacob_c/32/1532_2.png) [@jacob\_c](https://forum.makecode.com/u/jacob_c)\
**Post date:** [October 7, 2020, 10:04pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/36 "2020-10-07T22:04:01Z")

</div>

> [@Dreadmask197](#):
>
> Do you know what to do?

Oooh, ooh… I do!

While you’re `for`-ing over your index value, you want to position your newly created sprite onto a grid? If we think about the grid first as indexes, we get:

```auto
0 1 2 3
4 5 6 7
8 etc..

```

and if we instead think of them as `{ col, row }` coordinates, we’d get something like

```auto
{0,0} {1,0} {2,0} {3,0}
{0,1} {1,1} {2,1} {3,1}
{0,2} etc.

```

If you stare for awhile at these two tables, you’ll start to notice a few things:

In the top table, the left-most column counts `0, 4, 8`—and if we look at the row numbers from the bottom table, those count `0, 1, 2`. So it seems like there’s some relationship between **division** of the index by four and the row number.

Similarly, but maybe less obvious, the pattern of `0, 1, 2, 3` repeats for the column numbers over every row—these are like the **remainders** after performing that division:

```auto
4 / 4 = 1 remainder 0
5 / 4 = 1 remainder 1
6 / 4 = 1 remainder 2
7 / 4 = 1 remainder 3
8 / 4 = 2 remainder 0
etc.

```

Well, we have blocks that can compute both of these values:

 ![Screen Shot 2020-10-07 at 2.55.59 PM](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/f/f5201aff6f45387e48aacf7eebc7ce3d833f4a55.png)

I’m using the “integer division” block because that throws away the decimal part of the division and just keeps the whole number. (You could achieve a similar result with rounding.)

There’s a little bit of bookkeeping, once you’ve computed cell / row values to space them out well on the screen that involves a little bit more basic math. Here’s a screenshot of the whole thing:

 ![Screen Shot 2020-10-07 at 2.59.38 PM](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/c/c18a2930f64822e15c6aae9af1a83d00b7fda3d8.png)

… you can of course tweak `columnCount` and `cellSize` and `offset` to adjust the layout/positioning of your grid.

Does this help?

---

<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, 10:45pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/37 "2020-10-07T22:45:01Z")

</div>

Should I make a new Function or keep it in my other function

---

<div class="post-metadata">

**Author:** ![jacob\_c](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jacob_c/32/1532_2.png) [@jacob\_c](https://forum.makecode.com/u/jacob_c)\
**Post date:** [October 7, 2020, 11:12pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/38 "2020-10-07T23:12:23Z")

</div>

Oh you can roll it into your existing loop for sure. I just made a new function because I didn’t have your code handy.

(I’d just make sure that the things like `columnCount`, `cellSize` and `offset` are set _outside_ of the loop.)

---

<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, 11:39pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/39 "2020-10-07T23:39:00Z")

</div>

I guess I replace your sprite with a text sprite.

---

<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, 11:57pm UTC](https://forum.makecode.com/t/is-there-any-shorter-way-i-can-do-this/3787/40 "2020-10-07T23:57:39Z")

</div>

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

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

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