Discuss Scratch

angeltra24
New to Scratch
8 posts

looping through a list

Hi
I do have another forum post but i am getting more confused with the responses so i will try to explain, maybe easier.

I am creating a simon says games as part of my assignment
most of the script cant be edited except to scripts with “when i receive” hat blocks
the first hat block picks a random number that is associated with a colour and place it in a list,called colours
then it, puts them into another list called “sequence” list in a random order.

the second hat block “when i receive” then has to loop through the items in the 2nd list in order and broadcast them to the relevant sprites.
can i do that lol nope been on it for 3 days now and losing the will to live.
please see jpeg attached. http://imageshack.com/a/img823/2347/h6e6.jpg
Fjpackard
Scratcher
32 posts

looping through a list

To loop through a list, try something like this:

when green flag clicked
set [num v] to [1]
repeat (length of [list v])
set [currentItem v] to (item (num v) of [list v])
change [num v] by (1)
end

Then each time you loop you can do something with the variable currentItem.

Hope this helps!

Cheers,
Fjpackard.



“ Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. ”
drmcw
Scratcher
1000+ posts

looping through a list

In create new sequence what is
change [colourPosition v] by (COLOURS)
supposed to do? I think its deleteable.
Your play sequence just seems plain wrong. Try
when I receive [play sequence v]
set [index v] to [1]
repeat (length of [sequenceList v])
if <(item (index) of [sequenceList v]) = [green]> then
set [colourValue v] to [green]
broadcast [playWedge v] and wait
else
... // the other colour tests here
end
change [index v] by (1)
end

Last edited by drmcw (Jan. 14, 2014 09:29:42)


10 !
ScratchVaders or Galaga?
Maybe Eliza can help you decide?
angeltra24
New to Scratch
8 posts

looping through a list

Superb superb thanks guys xx
Fjpackard
Scratcher
32 posts

looping through a list

angeltra24 wrote:

Superb superb thanks guys xx

No problem!



“ Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. ”
mr_Sav
New to Scratch
1 post

looping through a list

angeltra24 wrote:

Superb superb thanks guys xx

Hi Angeltra - I am stumped on the same 3c question - could you provide any assistance it is driving me mad! Thanks
gourls
New to Scratch
17 posts

looping through a list

guys did yous ever complete this? I am stuck on the same parts as you were and my assignment has to be in by tuesday please help
Evieh
New to Scratch
1 post

looping through a list

Did you figure this out yet? I'm so stuck
BubbleFish1108
Scratcher
7 posts

looping through a list

<[] contains [thing] ?>
HueHue7
New to Scratch
1 post

looping through a list

-

Last edited by HueHue7 (March 28, 2019 15:03:22)

Powered by DjangoBB