On the “screen gamepad thing” it says, (object Object)
Got it.
You have this block in your code:
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:
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.
}
}
What is current move and current sprite? I don’t know Javascript and only do block coding
This is really confusing right now
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.
You’re writing some really complex code! Be patient; you’ll get it. Keep asking questions!
Here’s an example. It’s a little simpler than what I was suggesting above.
A few things to notice here:
- Notice that
ShuffledList
has 20 items in it, numbered 0 to 19. You can makeShuffledList
as long as you want; it does not have to match the size ofNotationList
. - Related to the previous point,
NotationList
has 18 items in it, numbered 0 to 17. I changed the numbers for yourpick 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.
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.
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
@AlexK
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?
I’m going to go and change the font size and the problem is seeing why all the text is diagonal
Do you know how to get rid of the diagonal parts on the screen?
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?
Maybe like this:
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.
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:
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
{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:
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:
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:
… you can of course tweak columnCount
and cellSize
and offset
to adjust the layout/positioning of your grid.
Does this help?
Should I make a new Function or keep it in my other function
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.)
I guess I replace your sprite with a text sprite.